##### R CODE TO REPLICATE THE FIGURES AND TABLES INCLUDED IN 
##### Adrian Lucardi, "Strength in Expectation. Elections, Economic Performance and Authoritarian Breakdown," forthcoming at The Journal of Politics

## Loading the required R packages. Make sure to have them installed before proceeding. In order to install a package called "X", write install.packages("X")
library (digest)
library (dplyr)
library (gstat)
library (ggplot2)
library (ggpubr)
library (lattice)
library (lfe)
library (lmtest)
library (MASS)
library (multiwayvcov)
library (plyr)
library (sandwich)
library (survival)
library (xtable)

## display options
options (digits=4, scipen=8, show.signif.stars=FALSE, tibble.print_max = Inf)

## working directory -> change this to the directory where your have your data
setwd ("/Users/adrianlucardi/Dropbox/Replication files/Lucardi 2018 JOP Strength in Expectation/")


###### DOWNLOADING AND PROCESSING THE DATA

## getting the dataset
baseFull <- read.csv ("Autocracies Elections and the Economy 1946-2015.csv", sep=",", header=TRUE)  ## all country-years, including democratic ones

## creating a couple of additional variables
baseFull$year.f <- factor (baseFull$year) ## for the fixed effects
baseFull$coldWar <- with (baseFull, ifelse (year <= 1989, 1, 0)) ## Cold War dummy for the GLM's
summary (baseFull); dim (baseFull)

## selecting the subsamples we'll use in the analysis

# (a) Main dataset: only EARs or closed authoritarian
baseMain <- baseFull[!is.na (baseFull$regime) & (baseFull$regime=="closed" | baseFull$regime=="EAR"),]
baseMain$democracy <- NULL
baseMain$provisional <- NULL
baseMain$autocracy <- NULL

# re-factorizing
baseMain$idRegime <- factor (baseMain$idRegime)
baseMain$country <- factor (baseMain$country)
baseMain$regime <- factor (baseMain$regime)
baseMain$region <- factor (baseMain$region)
baseMain$howEnded <- factor (baseMain$howEnded)
baseMain$endSource <- factor (baseMain$endSource)

# (ordered factors, which correspond to scheduled elections)
baseMain$yElecEf <- factor (baseMain$yElecEf, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain$yComLf <- factor (baseMain$yComLf, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain$yComLfreg <- factor (baseMain$yComLfreg, levels=c ("Never", "This year (EAR)", "This year (closed)", "Other year"), ordered=F)
baseMain$yComEf <- factor (baseMain$yComEf, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain$yComEfreg <- factor (baseMain$yComEfreg, levels=c ("Never", "This year (EAR)", "This year (closed)", "Other year"), ordered=F)
baseMain$yElecEfcomp <- factor (baseMain$yElecEfcomp, levels=c ("Never", "This year (EAR)", "This year (closed)", "Other year (EAR)", "Other year (closed)"), ordered=F)
baseMain$ynoComEf <- factor (baseMain$ynoComEf, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain$yComEfleg <- factor (baseMain$yComEfleg, levels=c ("Never", "This year (both)", "This year (executive)", "This year (legislative)", "Other year (both)"), ordered=F)
baseMain$yComLflied <- factor (baseMain$yComLflied, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain$yComEflied <- factor (baseMain$yComEflied, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain$ynoComEflied <- factor (baseMain$ynoComEflied, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain$yComLfvdem <- factor (baseMain$yComLfvdem, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain$yComEfvdem <- factor (baseMain$yComEfvdem, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain$ynoComEfvdem <- factor (baseMain$ynoComEfvdem, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain$yComOnlyLf <- factor (baseMain$yComOnlyLf, levels=c ("Never", "This year", "Other year", "This year (both)"), ordered=F)
baseMain$yComOnlyLflied <- factor (baseMain$yComOnlyLflied, levels=c ("Never", "This year", "Other year", "This year (both)"), ordered=F)
baseMain$yComOnlyLfvdem <- factor (baseMain$yComOnlyLfvdem, levels=c ("Never", "This year", "Other year", "This year (both)"), ordered=F)

# (dummies for some of the levels -> we'll need them for the interactions)
baseMain$yComEfNever <- with (baseMain, ifelse (yComEf=="Never", 1, 0))
baseMain$yComEfThis_year <- with (baseMain, ifelse (yComEf=="This year", 1, 0))
baseMain$yComEfOther_year <- with (baseMain, ifelse (yComEf=="Other year", 1, 0))
baseMain$ynoComEfNever <- with (baseMain, ifelse (ynoComEf=="Never", 1, 0))
baseMain$ynoComEfThis_year <- with (baseMain, ifelse (ynoComEf=="This year", 1, 0))
baseMain$ynoComEfOther_year <- with (baseMain, ifelse (ynoComEf=="Other year", 1, 0))
baseMain$yComOnlyLfNever <- with (baseMain, ifelse (yComOnlyLf=="Never", 1, 0))
baseMain$yComOnlyLfThis_year <- with (baseMain, ifelse (yComOnlyLf=="This year", 1, 0))
baseMain$yComOnlyLfOther_year <- with (baseMain, ifelse (yComOnlyLf=="Other year", 1, 0))
baseMain$yComOnlyLfThis_year_both <- with (baseMain, ifelse (yComOnlyLf=="This year (both)", 1, 0))
summary (baseMain); dim (baseMain)


## Maddison subsample -> country-years for which there is data from Maddison
maddMain <- baseMain[!is.na (baseMain$madddGDPHead_lag),]

# re-factorizing
maddMain$idRegime <- factor (maddMain$idRegime)
maddMain$country <- factor (maddMain$country)
maddMain$regime <- factor (maddMain$regime)
maddMain$region <- factor (maddMain$region)
maddMain$howEnded <- factor (maddMain$howEnded)
maddMain$endSource <- factor (maddMain$endSource)

# (ordered factors, which correspond to scheduled elections)
maddMain$yElecEf <- factor (maddMain$yElecEf, levels=c ("Never", "This year", "Other year"), ordered=F)
maddMain$yComLf <- factor (maddMain$yComLf, levels=c ("Never", "This year", "Other year"), ordered=F)
maddMain$yComLfreg <- factor (maddMain$yComLfreg, levels=c ("Never", "This year (EAR)", "This year (closed)", "Other year"), ordered=F)
maddMain$yComEf <- factor (maddMain$yComEf, levels=c ("Never", "This year", "Other year"), ordered=F)
maddMain$yComEfreg <- factor (maddMain$yComEfreg, levels=c ("Never", "This year (EAR)", "This year (closed)", "Other year"), ordered=F)
maddMain$yElecEfcomp <- factor (maddMain$yElecEfcomp, levels=c ("Never", "This year (EAR)", "This year (closed)", "Other year (EAR)", "Other year (closed)"), ordered=F)
maddMain$ynoComEf <- factor (maddMain$ynoComEf, levels=c ("Never", "This year", "Other year"), ordered=F)
maddMain$yComEfleg <- factor (maddMain$yComEfleg, levels=c ("Never", "This year (both)", "This year (executive)", "This year (legislative)", "Other year (both)"), ordered=F)
maddMain$yComLflied <- factor (maddMain$yComLflied, levels=c ("Never", "This year", "Other year"), ordered=F)
maddMain$yComEflied <- factor (maddMain$yComEflied, levels=c ("Never", "This year", "Other year"), ordered=F)
maddMain$ynoComEflied <- factor (maddMain$ynoComEflied, levels=c ("Never", "This year", "Other year"), ordered=F)
maddMain$yComLfvdem <- factor (maddMain$yComLfvdem, levels=c ("Never", "This year", "Other year"), ordered=F)
maddMain$yComEfvdem <- factor (maddMain$yComEfvdem, levels=c ("Never", "This year", "Other year"), ordered=F)
maddMain$ynoComEfvdem <- factor (maddMain$ynoComEfvdem, levels=c ("Never", "This year", "Other year"), ordered=F)
maddMain$yComOnlyLf <- factor (maddMain$yComOnlyLf, levels=c ("Never", "This year", "Other year", "This year (both)"), ordered=F)
maddMain$yComOnlyLflied <- factor (maddMain$yComOnlyLflied, levels=c ("Never", "This year", "Other year", "This year (both)"), ordered=F)
maddMain$yComOnlyLfvdem <- factor (maddMain$yComOnlyLfvdem, levels=c ("Never", "This year", "Other year", "This year (both)"), ordered=F)

# (dummies for some of the levels -> we'll need them for the interactions)
maddMain$yComEfNever <- with (maddMain, ifelse (yComEf=="Never", 1, 0))
maddMain$yComEfThis_year <- with (maddMain, ifelse (yComEf=="This year", 1, 0))
maddMain$yComEfOther_year <- with (maddMain, ifelse (yComEf=="Other year", 1, 0))
maddMain$ynoComEfNever <- with (maddMain, ifelse (ynoComEf=="Never", 1, 0))
maddMain$ynoComEfThis_year <- with (maddMain, ifelse (ynoComEf=="This year", 1, 0))
maddMain$ynoComEfOther_year <- with (maddMain, ifelse (ynoComEf=="Other year", 1, 0))
maddMain$yComOnlyLfNever <- with (maddMain, ifelse (yComOnlyLf=="Never", 1, 0))
maddMain$yComOnlyLfThis_year <- with (maddMain, ifelse (yComOnlyLf=="This year", 1, 0))
maddMain$yComOnlyLfOther_year <- with (maddMain, ifelse (yComOnlyLf=="Other year", 1, 0))
maddMain$yComOnlyLfThis_year_both <- with (maddMain, ifelse (yComOnlyLf=="This year (both)", 1, 0))
summary (maddMain); dim (maddMain)

## calculating the unit means for the probit analyses -> note we must include the means for all interaction terms as well
maddMainMeans <- as.data.frame (with (maddMain, factor (names (by (comE, idRegime, mean)))))
colnames (maddMainMeans) <- "idRegime"
maddMainMeans$comE <- with (maddMain, by (comE, idRegime, mean))[]
maddMainMeans$ear <- with (maddMain, by (ear, idRegime, mean))[]
maddMainMeans$comE_ear <- with (maddMain, by (comE*ear, idRegime, mean))[]
maddMainMeans$madddGDPHead_lag <- with (maddMain, by (madddGDPHead_lag, idRegime, mean))[]
maddMainMeans$madddGDPHead_lag_comE <- with (maddMain, by (madddGDPHead_lag*comE, idRegime, mean))[]
maddMainMeans$madddGDPHead_lag_ear <- with (maddMain, by (madddGDPHead_lag*ear, idRegime, mean))[]
maddMainMeans$madddGDPHead_lag_comE_ear <- with (maddMain, by (madddGDPHead_lag*comE*ear, idRegime, mean))[]
maddMainMeans$nocomE <- with (maddMain, by (nocomE, idRegime, mean))[]
maddMainMeans$earNoComp <- with (maddMain, by (earNoComp, idRegime, mean))[]
maddMainMeans$nocomE_earNoComp <- with (maddMain, by (nocomE*earNoComp, idRegime, mean))[]
maddMainMeans$madddGDPHead_lag_nocomE <- with (maddMain, by (madddGDPHead_lag*nocomE, idRegime, mean))[]
maddMainMeans$madddGDPHead_lag_earNoComp <- with (maddMain, by (madddGDPHead_lag*earNoComp, idRegime, mean))[]
maddMainMeans$madddGDPHead_lag_nocomE_earNoComp <- with (maddMain, by (madddGDPHead_lag*nocomE*earNoComp, idRegime, mean))[]
maddMainMeans$comL2 <- with (maddMain, by (comL2, idRegime, mean))[]
maddMainMeans$comL2_ear <- with (maddMain, by (comL2*ear, idRegime, mean))[]
maddMainMeans$madddGDPHead_lag_comL2 <- with (maddMain, by (madddGDPHead_lag*comL2, idRegime, mean))[]
maddMainMeans$madddGDPHead_lag_comL2_ear <- with (maddMain, by (madddGDPHead_lag*comL2*ear, idRegime, mean))[]
maddMainMeans$yComEfThis_year <- with (maddMain, by (yComEfThis_year, idRegime, mean))[]
maddMainMeans$yComEfOther_year <- with (maddMain, by (yComEfOther_year, idRegime, mean))[]
maddMainMeans$madddGDPHead_lag_yComEfThis_year <- with (maddMain, by (madddGDPHead_lag*yComEfThis_year, idRegime, mean))[]
maddMainMeans$madddGDPHead_lag_yComEfOther_year <- with (maddMain, by (madddGDPHead_lag*yComEfOther_year, idRegime, mean))[]
maddMainMeans$ynoComEfThis_year <- with (maddMain, by (ynoComEfThis_year, idRegime, mean))[]
maddMainMeans$ynoComEfOther_year <- with (maddMain, by (ynoComEfOther_year, idRegime, mean))[]
maddMainMeans$madddGDPHead_lag_ynoComEfThis_year <- with (maddMain, by (madddGDPHead_lag*ynoComEfThis_year, idRegime, mean))[]
maddMainMeans$madddGDPHead_lag_ynoComEfOther_year <- with (maddMain, by (madddGDPHead_lag*ynoComEfOther_year, idRegime, mean))[]
maddMainMeans$yComOnlyLfThis_year <- with (maddMain, by (yComOnlyLfThis_year, idRegime, mean))[]
maddMainMeans$yComOnlyLfOther_year <- with (maddMain, by (yComOnlyLfOther_year, idRegime, mean))[]
maddMainMeans$yComOnlyLfThis_year_both <- with (maddMain, by (yComOnlyLfThis_year_both, idRegime, mean))[]
maddMainMeans$madddGDPHead_lag_yComOnlyLfThis_year <- with (maddMain, by (madddGDPHead_lag*yComOnlyLfThis_year, idRegime, mean))[]
maddMainMeans$madddGDPHead_lag_yComOnlyLfOther_year <- with (maddMain, by (madddGDPHead_lag*yComOnlyLfOther_year, idRegime, mean))[]
maddMainMeans$madddGDPHead_lag_yComOnlyLfThis_year_both <- with (maddMain, by (madddGDPHead_lag*yComOnlyLfThis_year_both, idRegime, mean))[]
maddMainMeans$maddGDPHead_lag_log <- with (maddMain, by (log(maddGDPHead_lag), idRegime, mean))[]
maddMainMeans$propDemo <- with (maddMain, by (propDemo, idRegime, mean))[]

colnames (maddMainMeans)[-1] <- paste (colnames (maddMainMeans)[-1], "mean", sep="_")
summary (maddMainMeans); dim (maddMainMeans)

# ditto, but restricting the sample to observations for which we have oil data
maddMainMeans2 <- as.data.frame (with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], factor (names (by (comE, idRegime, mean)))))
colnames (maddMainMeans2) <- "idRegime"
maddMainMeans2$comE <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (comE, idRegime, mean))[]
maddMainMeans2$ear <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (ear, idRegime, mean))[]
maddMainMeans2$comE_ear <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (comE*ear, idRegime, mean))[]
maddMainMeans2$madddGDPHead_lag <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (madddGDPHead_lag, idRegime, mean))[]
maddMainMeans2$madddGDPHead_lag_comE <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (madddGDPHead_lag*comE, idRegime, mean))[]
maddMainMeans2$madddGDPHead_lag_ear <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (madddGDPHead_lag*ear, idRegime, mean))[]
maddMainMeans2$madddGDPHead_lag_comE_ear <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (madddGDPHead_lag*comE*ear, idRegime, mean))[]
maddMainMeans2$nocomE <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (nocomE, idRegime, mean))[]
maddMainMeans2$earNoComp <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (earNoComp, idRegime, mean))[]
maddMainMeans2$nocomE_earNoComp <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (nocomE*earNoComp, idRegime, mean))[]
maddMainMeans2$madddGDPHead_lag_nocomE <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (madddGDPHead_lag*nocomE, idRegime, mean))[]
maddMainMeans2$madddGDPHead_lag_earNoComp <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (madddGDPHead_lag*earNoComp, idRegime, mean))[]
maddMainMeans2$madddGDPHead_lag_nocomE_earNoComp <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (madddGDPHead_lag*nocomE*earNoComp, idRegime, mean))[]
maddMainMeans2$comL2 <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (comL2, idRegime, mean))[]
maddMainMeans2$comL2_ear <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (comL2*ear, idRegime, mean))[]
maddMainMeans2$madddGDPHead_lag_comL2 <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (madddGDPHead_lag*comL2, idRegime, mean))[]
maddMainMeans2$madddGDPHead_lag_comL2_ear <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (madddGDPHead_lag*comL2*ear, idRegime, mean))[]
maddMainMeans2$yComEfThis_year <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (yComEfThis_year, idRegime, mean))[]
maddMainMeans2$yComEfOther_year <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (yComEfOther_year, idRegime, mean))[]
maddMainMeans2$madddGDPHead_lag_yComEfThis_year <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (madddGDPHead_lag*yComEfThis_year, idRegime, mean))[]
maddMainMeans2$madddGDPHead_lag_yComEfOther_year <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (madddGDPHead_lag*yComEfOther_year, idRegime, mean))[]
maddMainMeans2$ynoComEfThis_year <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (ynoComEfThis_year, idRegime, mean))[]
maddMainMeans2$ynoComEfOther_year <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (ynoComEfOther_year, idRegime, mean))[]
maddMainMeans2$madddGDPHead_lag_ynoComEfThis_year <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (madddGDPHead_lag*ynoComEfThis_year, idRegime, mean))[]
maddMainMeans2$madddGDPHead_lag_ynoComEfOther_year <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (madddGDPHead_lag*ynoComEfOther_year, idRegime, mean))[]
maddMainMeans2$yComOnlyLfThis_year <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (yComOnlyLfThis_year, idRegime, mean))[]
maddMainMeans2$yComOnlyLfOther_year <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (yComOnlyLfOther_year, idRegime, mean))[]
maddMainMeans2$yComOnlyLfThis_year_both <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (yComOnlyLfThis_year_both, idRegime, mean))[]
maddMainMeans2$madddGDPHead_lag_yComOnlyLfThis_year <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (madddGDPHead_lag*yComOnlyLfThis_year, idRegime, mean))[]
maddMainMeans2$madddGDPHead_lag_yComOnlyLfOther_year <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (madddGDPHead_lag*yComOnlyLfOther_year, idRegime, mean))[]
maddMainMeans2$madddGDPHead_lag_yComOnlyLfThis_year_both <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (madddGDPHead_lag*yComOnlyLfThis_year_both, idRegime, mean))[]
maddMainMeans2$maddGDPHead_lag_log <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (log(maddGDPHead_lag), idRegime, mean))[]
maddMainMeans2$propDemo <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (propDemo, idRegime, mean))[]
maddMainMeans2$oil_gas_valuePOP_2000_lag_log <- with (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], by (log (oil_gas_valuePOP_2000_lag+1), idRegime, mean))[]

colnames (maddMainMeans2)[-1] <- paste (colnames (maddMainMeans2)[-1], "mean2", sep="_")
summary (maddMainMeans2); dim (maddMainMeans2)

# merging
maddMain <- merge (maddMain, maddMainMeans, by="idRegime", all.x=T, all.y=T)
maddMain <- merge (maddMain, maddMainMeans2, by="idRegime", all.x=T, all.y=T)
summary (maddMain); dim (maddMain)


## PWT subsample -> country-years for which there is data from PWT 9.0
pwtMain <- baseMain[!is.na (baseMain$pwtdGDPHead_lag),]

# re-factorizing
pwtMain$idRegime <- factor (pwtMain$idRegime)
pwtMain$country <- factor (pwtMain$country)
pwtMain$regime <- factor (pwtMain$regime)
pwtMain$region <- factor (pwtMain$region)
pwtMain$howEnded <- factor (pwtMain$howEnded)
pwtMain$endSource <- factor (pwtMain$endSource)

summary (pwtMain); dim (pwtMain)


## WDI subsample -> country-years for which there is data from WDI
wdiMain <- baseMain[!is.na (baseMain$wdidGDPHead_lag),]

# re-factorizing
wdiMain$idRegime <- factor (wdiMain$idRegime)
wdiMain$country <- factor (wdiMain$country)
wdiMain$regime <- factor (wdiMain$regime)
wdiMain$region <- factor (wdiMain$region)
wdiMain$howEnded <- factor (wdiMain$howEnded)
wdiMain$endSource <- factor (wdiMain$endSource)

summary (wdiMain); dim (wdiMain)



# (b) Extended dataset: all autocracies
baseMain2 <- baseFull[!is.na (baseFull$regime) & baseFull$autocracy==1,]
baseMain2$democracy <- NULL
baseMain2$provisional <- NULL
baseMain2$autocracy <- NULL

# re-factorizing
baseMain2$idRegime <- factor (baseMain2$idRegime)
baseMain2$country <- factor (baseMain2$country)
baseMain2$regime <- factor (baseMain2$regime)
baseMain2$region <- factor (baseMain2$regime)
baseMain2$howEnded <- factor (baseMain2$howEnded)
baseMain2$endSource <- factor (baseMain2$endSource)

# (ordered factors, which correspond to scheduled elections)
baseMain2$yElecEf <- factor (baseMain2$yElecEf, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain2$yComLf <- factor (baseMain2$yComLf, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain2$yComLfreg <- factor (baseMain2$yComLfreg, levels=c ("Never", "This year (EAR)", "This year (closed)", "Other year"), ordered=F)
baseMain2$yComEf <- factor (baseMain2$yComEf, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain2$yComEfreg <- factor (baseMain2$yComEfreg, levels=c ("Never", "This year (EAR)", "This year (closed)", "Other year"), ordered=F)
baseMain2$yElecEfcomp <- factor (baseMain2$yElecEfcomp, levels=c ("Never", "This year (EAR)", "This year (closed)", "Other year (EAR)", "Other year (closed)"), ordered=F)
baseMain2$ynoComEf <- factor (baseMain2$ynoComEf, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain2$yComEfleg <- factor (baseMain2$yComEfleg, levels=c ("Never", "This year (both)", "This year (executive)", "This year (legislative)", "Other year (both)"), ordered=F)
baseMain2$yComLflied <- factor (baseMain2$yComLflied, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain2$yComEflied <- factor (baseMain2$yComEflied, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain2$ynoComEflied <- factor (baseMain2$ynoComEflied, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain2$yComLfvdem <- factor (baseMain2$yComLfvdem, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain2$yComEfvdem <- factor (baseMain2$yComEfvdem, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain2$ynoComEfvdem <- factor (baseMain2$ynoComEfvdem, levels=c ("Never", "This year", "Other year"), ordered=F)
baseMain2$yComOnlyLf <- factor (baseMain2$yComOnlyLf, levels=c ("Never", "This year", "Other year", "This year (both)"), ordered=F)
baseMain2$yComOnlyLflied <- factor (baseMain2$yComOnlyLflied, levels=c ("Never", "This year", "Other year", "This year (both)"), ordered=F)
baseMain2$yComOnlyLfvdem <- factor (baseMain2$yComOnlyLfvdem, levels=c ("Never", "This year", "Other year", "This year (both)"), ordered=F)

# (dummies for some of the levels -> we'll need them for the interactions)
baseMain2$yComEfNever <- with (baseMain2, ifelse (yComEf=="Never", 1, 0))
baseMain2$yComEfThis_year <- with (baseMain2, ifelse (yComEf=="This year", 1, 0))
baseMain2$yComEfOther_year <- with (baseMain2, ifelse (yComEf=="Other year", 1, 0))
baseMain2$ynoComEfNever <- with (baseMain2, ifelse (ynoComEf=="Never", 1, 0))
baseMain2$ynoComEfThis_year <- with (baseMain2, ifelse (ynoComEf=="This year", 1, 0))
baseMain2$ynoComEfOther_year <- with (baseMain2, ifelse (ynoComEf=="Other year", 1, 0))
baseMain2$yComOnlyLfNever <- with (baseMain2, ifelse (yComOnlyLf=="Never", 1, 0))
baseMain2$yComOnlyLfThis_year <- with (baseMain2, ifelse (yComOnlyLf=="This year", 1, 0))
baseMain2$yComOnlyLfOther_year <- with (baseMain2, ifelse (yComOnlyLf=="Other year", 1, 0))
baseMain2$yComOnlyLfThis_year_both <- with (baseMain2, ifelse (yComOnlyLf=="This year (both)", 1, 0))

# (for LIED data)
baseMain2$yComEfNeverlied <- with (baseMain2, ifelse (yComEflied=="Never", 1, 0))
baseMain2$yComEfThis_yearlied <- with (baseMain2, ifelse (yComEflied=="This year", 1, 0))
baseMain2$yComEfOther_yearlied <- with (baseMain2, ifelse (yComEflied=="Other year", 1, 0))
baseMain2$ynoComEfNeverlied <- with (baseMain2, ifelse (ynoComEflied=="Never", 1, 0))
baseMain2$ynoComEfThis_yearlied <- with (baseMain2, ifelse (ynoComEflied=="This year", 1, 0))
baseMain2$ynoComEfOther_yearlied <- with (baseMain2, ifelse (ynoComEflied=="Other year", 1, 0))
baseMain2$yComOnlyLfNeverlied <- with (baseMain2, ifelse (yComOnlyLflied=="Never", 1, 0))
baseMain2$yComOnlyLfThis_yearlied <- with (baseMain2, ifelse (yComOnlyLflied=="This year", 1, 0))
baseMain2$yComOnlyLfOther_yearlied <- with (baseMain2, ifelse (yComOnlyLflied=="Other year", 1, 0))
baseMain2$yComOnlyLfThis_year_bothlied <- with (baseMain2, ifelse (yComOnlyLflied=="This year (both)", 1, 0))

# (for V-Dem data)
baseMain2$yComEfNevervdem <- with (baseMain2, ifelse (yComEfvdem=="Never", 1, 0))
baseMain2$yComEfThis_yearvdem <- with (baseMain2, ifelse (yComEfvdem=="This year", 1, 0))
baseMain2$yComEfOther_yearvdem <- with (baseMain2, ifelse (yComEfvdem=="Other year", 1, 0))
baseMain2$ynoComEfNevervdem <- with (baseMain2, ifelse (ynoComEfvdem=="Never", 1, 0))
baseMain2$ynoComEfThis_yearvdem <- with (baseMain2, ifelse (ynoComEfvdem=="This year", 1, 0))
baseMain2$ynoComEfOther_yearvdem <- with (baseMain2, ifelse (ynoComEfvdem=="Other year", 1, 0))
baseMain2$yComOnlyLfNevervdem <- with (baseMain2, ifelse (yComOnlyLfvdem=="Never", 1, 0))
baseMain2$yComOnlyLfThis_yearvdem <- with (baseMain2, ifelse (yComOnlyLfvdem=="This year", 1, 0))
baseMain2$yComOnlyLfOther_yearvdem <- with (baseMain2, ifelse (yComOnlyLfvdem=="Other year", 1, 0))
baseMain2$yComOnlyLfThis_year_bothvdem <- with (baseMain2, ifelse (yComOnlyLfvdem=="This year (both)", 1, 0))

summary (baseMain2); dim (baseMain2)


## Maddison subsample
maddMain2 <- baseMain2[!is.na (baseMain2$madddGDPHead_lag),]

# re-factorizing
maddMain2$idRegime <- factor (maddMain2$idRegime)
maddMain2$country <- factor (maddMain2$country)
maddMain2$regime <- factor (maddMain2$regime)
maddMain2$region <- factor (maddMain2$region)
maddMain2$howEnded <- factor (maddMain2$howEnded)
maddMain2$endSource <- factor (maddMain2$endSource)


## LIED and V-Dem subsamples
maddMain2lied <- maddMain2[!is.na (maddMain2$earLIED),] ## if not coded as authoritarian by GWF, not in the sample; if NA for Maddison data, won't be able to include in the anyway
maddMain2vdem <- maddMain2[!is.na (maddMain2$earVDem),]




########## FITTING THE MODELS

### (1) Replicating the models reported in Tables 1, Tables A6-A7 and Figure 2: Main results (1xx models)

## Actual elections: 10x models

# 100 models: growth only
(sum.m100a <- summary (m100a <- felm (fail ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))  ## warnings reported. Don't worry
(sum.m100b <- summary (m100b <- felm (fail ~ madddGDPHead_lag + log(maddGDPHead_lag) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m100c <- summary (m100c <- felm (fail ~ madddGDPHead_lag + log (oil_gas_valuePOP_2000_lag+1) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m100d <- summary (m100d <- felm (fail ~ madddGDPHead_lag + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m100e <- summary (m100e <- felm (fail ~ madddGDPHead_lag + propElections + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m100f <- summary (m100f <- felm (fail ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m100f2 <- summary (m100f2 <- felm (fail ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))

# 101 models: elections only
(sum.m101a <- summary (m101a <- felm (fail ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m101b <- summary (m101b <- felm (fail ~ comE + log(maddGDPHead_lag) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m101c <- summary (m101c <- felm (fail ~ comE + log (oil_gas_valuePOP_2000_lag+1) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m101d <- summary (m101d <- felm (fail ~ comE + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m101e <- summary (m101e <- felm (fail ~ comE + propElections + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m101f <- summary (m101f <- felm (fail ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m101f2 <- summary (m101f2 <- felm (fail ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))

# 102 models: growth*elections
(sum.m102a <- summary (m102a <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m102b <- summary (m102b <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m102c <- summary (m102c <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log (oil_gas_valuePOP_2000_lag+1) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m102d <- summary (m102d <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m102e <- summary (m102e <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + propElections + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m102f <- summary (m102f <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m102f2 <- summary (m102f2 <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))

# 103 models: growth*elections*EAR
(sum.m103a <- summary (m103a <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m103b <- summary (m103b <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m103c <- summary (m103c <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log (oil_gas_valuePOP_2000_lag+1) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m103d <- summary (m103d <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m103e <- summary (m103e <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + propElections + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m103f <- summary (m103f <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m103f2 <- summary (m103f2 <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))

# 104 models: non-competitive executive elections only*growth
(sum.m104a <- summary (m104a <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m104b <- summary (m104b <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + log(maddGDPHead_lag) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m104c <- summary (m104c <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + log (oil_gas_valuePOP_2000_lag+1) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m104d <- summary (m104d <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m104e <- summary (m104e <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + propElections + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m104f <- summary (m104f <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m104f2 <- summary (m104f2 <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))

# 105 models: non-competitive executive elections only*growth*EAR (non-competitive)
(sum.m105a <- summary (m105a <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m105b <- summary (m105b <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m105c <- summary (m105c <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log (oil_gas_valuePOP_2000_lag+1) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m105d <- summary (m105d <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m105e <- summary (m105e <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + propElections + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m105f <- summary (m105f <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m105f2 <- summary (m105f2 <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))

# 106 models: growth*executive (competitive) + growth*executive (non-competitive)
(sum.m106a <- summary (m106a <- felm (fail ~ comE + nocomE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m106b <- summary (m106b <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + nocomE + I(madddGDPHead_lag*nocomE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m106c <- summary (m106c <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + nocomE + I(madddGDPHead_lag*nocomE) + log(maddGDPHead_lag) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m106d <- summary (m106d <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + nocomE + I(madddGDPHead_lag*nocomE) + log (oil_gas_valuePOP_2000_lag+1) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m106e <- summary (m106e <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + nocomE + I(madddGDPHead_lag*nocomE) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m106f <- summary (m106f <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + nocomE + I(madddGDPHead_lag*nocomE) + propElections + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m106g <- summary (m106g <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + nocomE + I(madddGDPHead_lag*nocomE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m106g2 <- summary (m106g2 <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + nocomE + I(madddGDPHead_lag*nocomE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))

# 107 models: growth*executive (competitive)*EAR + growth*executive (non-competitive)*EAR (non-competitive)
(sum.m107a <- summary (m107a <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m107b <- summary (m107b <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m107c <- summary (m107c <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log (oil_gas_valuePOP_2000_lag+1) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m107d <- summary (m107d <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m107e <- summary (m107e <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + propElections + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m107f <- summary (m107f <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m107f2 <- summary (m107f2 <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))

# 108 models: competitive legislative elections that do NOT coincide with executive ones*growth
(sum.m108a <- summary (m108a <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m108b <- summary (m108b <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + log(maddGDPHead_lag) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m108c <- summary (m108c <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + log (oil_gas_valuePOP_2000_lag+1) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m108d <- summary (m108d <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m108e <- summary (m108e <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + propElections + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m108f <- summary (m108f <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m108f2 <- summary (m108f2 <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))

# 109 models: competitive legislative elections that do NOT coincide with executive ones*growth*EAR (non-competitive)
(sum.m109a <- summary (m109a <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m109b <- summary (m109b <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m109c <- summary (m109c <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log (oil_gas_valuePOP_2000_lag+1) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m109d <- summary (m109d <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m109e <- summary (m109e <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + propElections + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m109f <- summary (m109f <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m109f2 <- summary (m109f2 <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))


## Scheduled elections: 11x models

# 110 models: elections only
(sum.m110a <- summary (m110a <- felm (fail ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m110b <- summary (m110b <- felm (fail ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m110c <- summary (m110c <- felm (fail ~ yComEfThis_year + yComEfOther_year + log (oil_gas_valuePOP_2000_lag+1) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m110d <- summary (m110d <- felm (fail ~ yComEfThis_year + yComEfOther_year + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m110e <- summary (m110e <- felm (fail ~ yComEfThis_year + yComEfOther_year + propElections + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m110f <- summary (m110f <- felm (fail ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m110f2 <- summary (m110f2 <- felm (fail ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))

# 111 models: growth*elections
(sum.m111a <- summary (m111a <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m111b <- summary (m111b <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m111c <- summary (m111c <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log (oil_gas_valuePOP_2000_lag+1) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m111d <- summary (m111d <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m111e <- summary (m111e <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + propElections + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m111f <- summary (m111f <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m111f2 <- summary (m111f2 <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))

# 112 models: scheduled non-competitive executive elections only
(sum.m112a <- summary (m112a <- felm (fail ~ ynoComEf + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m112b <- summary (m112b <- felm (fail ~ ynoComEf + log(maddGDPHead_lag) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m112c <- summary (m112c <- felm (fail ~ ynoComEf + log (oil_gas_valuePOP_2000_lag+1) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m112d <- summary (m112d <- felm (fail ~ ynoComEf + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m112e <- summary (m112e <- felm (fail ~ ynoComEf + propElections + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m112f <- summary (m112f <- felm (fail ~ ynoComEf + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m112f2 <- summary (m112f2 <- felm (fail ~ ynoComEf + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))

# 113 models: growth*scheduled non-competitive executive elections
(sum.m113a <- summary (m113a <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m113b <- summary (m113b <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m113c <- summary (m113c <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log (oil_gas_valuePOP_2000_lag+1) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m113d <- summary (m113d <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m113e <- summary (m113e <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + propElections + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m113f <- summary (m113f <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m113f2 <- summary (m113f2 <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))

# 114 models: scheduled competitive AND non-competitive executive elections
(sum.m114a <- summary (m114a <- felm (fail ~ yElecEfcomp + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m114b <- summary (m114b <- felm (fail ~ yElecEfcomp + log(maddGDPHead_lag) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m114c <- summary (m114c <- felm (fail ~ yElecEfcomp + log (oil_gas_valuePOP_2000_lag+1) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m114d <- summary (m114d <- felm (fail ~ yElecEfcomp + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m114e <- summary (m114e <- felm (fail ~ yElecEfcomp + propElections + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m114f <- summary (m114f <- felm (fail ~ yElecEfcomp + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# 115 models: growth*scheduled competitive AND non-competitive executive elections
(sum.m115a <- summary (m115a <- felm (fail ~ madddGDPHead_lag*yElecEfcomp + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m115b <- summary (m115b <- felm (fail ~ madddGDPHead_lag*yElecEfcomp + log(maddGDPHead_lag) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m115c <- summary (m115c <- felm (fail ~ madddGDPHead_lag*yElecEfcomp + log (oil_gas_valuePOP_2000_lag+1) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m115d <- summary (m115d <- felm (fail ~ madddGDPHead_lag*yElecEfcomp + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m115e <- summary (m115e <- felm (fail ~ madddGDPHead_lag*yElecEfcomp + propElections + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m115f <- summary (m115f <- felm (fail ~ madddGDPHead_lag*yElecEfcomp + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# 116 models: (competitive) legislative elections only
(sum.m116a <- summary (m116a <- felm (fail ~ yComOnlyLf + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m116b <- summary (m116b <- felm (fail ~ yComOnlyLf + log(maddGDPHead_lag) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m116c <- summary (m116c <- felm (fail ~ yComOnlyLf + log (oil_gas_valuePOP_2000_lag+1) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m116d <- summary (m116d <- felm (fail ~ yComOnlyLf + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m116e <- summary (m116e <- felm (fail ~ yComOnlyLf + propElections + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m116f <- summary (m116f <- felm (fail ~ yComOnlyLf + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m116f2 <- summary (m116f2 <- felm (fail ~ yComOnlyLf + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))

# 117 models: growth*(competitive) legislative elections only
(sum.m117a <- summary (m117a <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m117b <- summary (m117b <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m117c <- summary (m117c <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log (oil_gas_valuePOP_2000_lag+1) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m117d <- summary (m117d <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m117e <- summary (m117e <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + propElections + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m117f <- summary (m117f <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m117f2 <- summary (m117f2 <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))



### (2) Replicating the models reported in Table 2, Tables A8-A17, and Figures A2 to A11: Alternative outcomes (2xx models)

## (2.0) 2x0 models: protest dummy

# Growth only: 200 models
(sum.m200a <- summary (m200a <- felm (protestD ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m200b <- summary (m200b <- felm (protestD ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Actual elections: 210 models
(sum.m210a <- summary (m210a <- felm (protestD ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m210b <- summary (m210b <- felm (protestD ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m210c <- summary (m210c <- felm (protestD ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m210d <- summary (m210d <- felm (protestD ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m210e <- summary (m210e <- felm (protestD ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m210f <- summary (m210f <- felm (protestD ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m210f2 <- summary (m210f2 <- felm (protestD ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m210g <- summary (m210g <- felm (protestD ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m210h <- summary (m210h <- felm (protestD ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m210i <- summary (m210i <- felm (protestD ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m210j <- summary (m210j <- felm (protestD ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Scheduled elections: 220 models
(sum.m220a <- summary (m220a <- felm (protestD ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m220b <- summary (m220b <- felm (protestD ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m220e <- summary (m220e <- felm (protestD ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m220f <- summary (m220f <- felm (protestD ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m220f2 <- summary (m220f2 <- felm (protestD ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m220g <- summary (m220g <- felm (protestD ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m220h <- summary (m220h <- felm (protestD ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m220i <- summary (m220i <- felm (protestD ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m220j <- summary (m220j <- felm (protestD ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))


## (2.1) 2x1 models: violent protest dummy

# Growth only: 201 models
(sum.m201a <- summary (m201a <- felm (protestViolentD ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m201b <- summary (m201b <- felm (protestViolentD ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Actual elections: 211 models
(sum.m211a <- summary (m211a <- felm (protestViolentD ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m211b <- summary (m211b <- felm (protestViolentD ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m211c <- summary (m211c <- felm (protestViolentD ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m211d <- summary (m211d <- felm (protestViolentD ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m211e <- summary (m211e <- felm (protestViolentD ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m211f <- summary (m211f <- felm (protestViolentD ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m211f2 <- summary (m211f2 <- felm (protestViolentD ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m211g <- summary (m211g <- felm (protestViolentD ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m211h <- summary (m211h <- felm (protestViolentD ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m211i <- summary (m211i <- felm (protestViolentD ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m211j <- summary (m211j <- felm (protestViolentD ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Scheduled elections: 221 models
(sum.m221a <- summary (m221a <- felm (protestViolentD ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m221b <- summary (m221b <- felm (protestViolentD ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m221e <- summary (m221e <- felm (protestViolentD ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m221f <- summary (m221f <- felm (protestViolentD ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m221f2 <- summary (m221f2 <- felm (protestViolentD ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m221g <- summary (m221g <- felm (protestViolentD ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m221h <- summary (m221h <- felm (protestViolentD ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m221i <- summary (m221i <- felm (protestViolentD ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m221j <- summary (m221j <- felm (protestViolentD ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))


## (2.2) 2x2 models: democracy or provisional government immediately after breakdown

# Growth only: 202 models
(sum.m202a <- summary (m202a <- felm (ttd2 ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m202b <- summary (m202b <- felm (ttd2 ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Actual elections: 212 models
(sum.m212a <- summary (m212a <- felm (ttd2 ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m212b <- summary (m212b <- felm (ttd2 ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m212c <- summary (m212c <- felm (ttd2 ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m212d <- summary (m212d <- felm (ttd2 ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m212e <- summary (m212e <- felm (ttd2 ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m212f <- summary (m212f <- felm (ttd2 ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m212f2 <- summary (m212f2 <- felm (ttd2 ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m212g <- summary (m212g <- felm (ttd2 ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m212h <- summary (m212h <- felm (ttd2 ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m212i <- summary (m212i <- felm (ttd2 ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m212j <- summary (m212j <- felm (ttd2 ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Scheduled elections: 222 models
(sum.m222a <- summary (m222a <- felm (ttd2 ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m222b <- summary (m222b <- felm (ttd2 ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m222e <- summary (m222e <- felm (ttd2 ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m222f <- summary (m222f <- felm (ttd2 ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m222f2 <- summary (m222f2 <- felm (ttd2 ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m222g <- summary (m222g <- felm (ttd2 ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m222h <- summary (m222h <- felm (ttd2 ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m222i <- summary (m222i <- felm (ttd2 ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m222j <- summary (m222j <- felm (ttd2 ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))


## (2.3) 2x3 models: another autocracy immediately after breakdown

# Growth only: 203 models
(sum.m203a <- summary (m203a <- felm (tta ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m203b <- summary (m203b <- felm (tta ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Actual elections: 213 models
(sum.m213a <- summary (m213a <- felm (tta ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m213b <- summary (m213b <- felm (tta ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m213c <- summary (m213c <- felm (tta ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m213d <- summary (m213d <- felm (tta ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m213e <- summary (m213e <- felm (tta ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m213f <- summary (m213f <- felm (tta ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m213f2 <- summary (m213f2 <- felm (tta ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m213g <- summary (m213g <- felm (tta ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m213h <- summary (m213h <- felm (tta ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m213i <- summary (m213i <- felm (tta ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m213j <- summary (m213j <- felm (tta ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Scheduled elections: 223 models
(sum.m223a <- summary (m223a <- felm (tta ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m223b <- summary (m223b <- felm (tta ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m223e <- summary (m223e <- felm (tta ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m223f <- summary (m223f <- felm (tta ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m223f2 <- summary (m223f2 <- felm (tta ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m223g <- summary (m223g <- felm (tta ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m223h <- summary (m223h <- felm (tta ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m223i <- summary (m223i <- felm (tta ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m223j <- summary (m223j <- felm (tta ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))


## (2.4) 2x4 models: regime ended from the inside

# Growth only: 204 models
(sum.m204a <- summary (m204a <- felm (endInsider ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m204b <- summary (m204b <- felm (endInsider ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Actual elections: 214 models
(sum.m214a <- summary (m214a <- felm (endInsider ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m214b <- summary (m214b <- felm (endInsider ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m214c <- summary (m214c <- felm (endInsider ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m214d <- summary (m214d <- felm (endInsider ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m214e <- summary (m214e <- felm (endInsider ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m214f <- summary (m214f <- felm (endInsider ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m214f2 <- summary (m214f2 <- felm (endInsider ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m214g <- summary (m214g <- felm (endInsider ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m214h <- summary (m214h <- felm (endInsider ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m214i <- summary (m214i <- felm (endInsider ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m214j <- summary (m214j <- felm (endInsider ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Scheduled elections: 224 models
(sum.m224a <- summary (m224a <- felm (endInsider ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m224b <- summary (m224b <- felm (endInsider ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m224e <- summary (m224e <- felm (endInsider ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m224f <- summary (m224f <- felm (endInsider ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m224f2 <- summary (m224f2 <- felm (endInsider ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m224g <- summary (m224g <- felm (endInsider ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m224h <- summary (m224h <- felm (endInsider ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m224i <- summary (m224i <- felm (endInsider ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m224j <- summary (m224j <- felm (endInsider ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))


## (2.5) 2x5 models: regime ended from the outside

# Growth only: 205 models
(sum.m205a <- summary (m205a <- felm (endOutsider ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m205b <- summary (m205b <- felm (endOutsider ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Actual elections: 215 models
(sum.m215a <- summary (m215a <- felm (endOutsider ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m215b <- summary (m215b <- felm (endOutsider ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m215c <- summary (m215c <- felm (endOutsider ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m215d <- summary (m215d <- felm (endOutsider ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m215e <- summary (m215e <- felm (endOutsider ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m215f <- summary (m215f <- felm (endOutsider ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m215f2 <- summary (m215f2 <- felm (endOutsider ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m215g <- summary (m215g <- felm (endOutsider ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m215h <- summary (m215h <- felm (endOutsider ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m215i <- summary (m215i <- felm (endOutsider ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m215j <- summary (m215j <- felm (endOutsider ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Scheduled elections: 225 models
(sum.m225a <- summary (m225a <- felm (endOutsider ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m225b <- summary (m225b <- felm (endOutsider ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m225e <- summary (m225e <- felm (endOutsider ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m225f <- summary (m225f <- felm (endOutsider ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m225f2 <- summary (m225f2 <- felm (endOutsider ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m225g <- summary (m225g <- felm (endOutsider ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m225h <- summary (m225h <- felm (endOutsider ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m225i <- summary (m225i <- felm (endOutsider ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m225j <- summary (m225j <- felm (endOutsider ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))


## (2.6) 2x6 models: regime ended voluntarily

# Growth only: 206 models
(sum.m206a <- summary (m206a <- felm (endVoluntary ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m206b <- summary (m206b <- felm (endVoluntary ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Actual elections: 216 models
(sum.m216a <- summary (m216a <- felm (endVoluntary ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m216b <- summary (m216b <- felm (endVoluntary ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m216c <- summary (m216c <- felm (endVoluntary ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m216d <- summary (m216d <- felm (endVoluntary ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m216e <- summary (m216e <- felm (endVoluntary ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m216f <- summary (m216f <- felm (endVoluntary ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m216f2 <- summary (m216f2 <- felm (endVoluntary ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m216g <- summary (m216g <- felm (endVoluntary ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m216h <- summary (m216h <- felm (endVoluntary ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m216i <- summary (m216i <- felm (endVoluntary ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m216j <- summary (m216j <- felm (endVoluntary ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Scheduled elections: 226 models
(sum.m226a <- summary (m226a <- felm (endVoluntary ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m226b <- summary (m226b <- felm (endVoluntary ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m226e <- summary (m226e <- felm (endVoluntary ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m226f <- summary (m226f <- felm (endVoluntary ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m226f2 <- summary (m226f2 <- felm (endVoluntary ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m226g <- summary (m226g <- felm (endVoluntary ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m226h <- summary (m226h <- felm (endVoluntary ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m226i <- summary (m226i <- felm (endVoluntary ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m226j <- summary (m226j <- felm (endVoluntary ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))


## (2.7) 2x7 models: at least one coup attempt during the year

# Growth only: 207 models
(sum.m207a <- summary (m207a <- felm (coup ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m207b <- summary (m207b <- felm (coup ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Actual elections: 217 models
(sum.m217a <- summary (m217a <- felm (coup ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m217b <- summary (m217b <- felm (coup ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m217c <- summary (m217c <- felm (coup ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m217d <- summary (m217d <- felm (coup ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m217e <- summary (m217e <- felm (coup ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m217f <- summary (m217f <- felm (coup ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m217f2 <- summary (m217f2 <- felm (coup ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m217g <- summary (m217g <- felm (coup ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m217h <- summary (m217h <- felm (coup ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m217i <- summary (m217i <- felm (coup ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m217j <- summary (m217j <- felm (coup ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Scheduled elections: 227 models
(sum.m227a <- summary (m227a <- felm (coup ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m227b <- summary (m227b <- felm (coup ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m227e <- summary (m227e <- felm (coup ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m227f <- summary (m227f <- felm (coup ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m227f2 <- summary (m227f2 <- felm (coup ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m227g <- summary (m227g <- felm (coup ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m227h <- summary (m227h <- felm (coup ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m227i <- summary (m227i <- felm (coup ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m227j <- summary (m227j <- felm (coup ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))


## (2.8) 2x8 models: successful coup during the year

# Growth only: 208 models
(sum.m208a <- summary (m208a <- felm (coupSuc ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m208b <- summary (m208b <- felm (coupSuc ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Actual elections: 218 models
(sum.m218a <- summary (m218a <- felm (coupSuc ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m218b <- summary (m218b <- felm (coupSuc ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m218c <- summary (m218c <- felm (coupSuc ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m218d <- summary (m218d <- felm (coupSuc ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m218e <- summary (m218e <- felm (coupSuc ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m218f <- summary (m218f <- felm (coupSuc ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m218f2 <- summary (m218f2 <- felm (coupSuc ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m218g <- summary (m218g <- felm (coupSuc ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m218h <- summary (m218h <- felm (coupSuc ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m218i <- summary (m218i <- felm (coupSuc ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m218j <- summary (m218j <- felm (coupSuc ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Scheduled elections: 228 models
(sum.m228a <- summary (m228a <- felm (coupSuc ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m228b <- summary (m228b <- felm (coupSuc ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m228e <- summary (m228e <- felm (coupSuc ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m228f <- summary (m228f <- felm (coupSuc ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m228f2 <- summary (m228f2 <- felm (coupSuc ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m228g <- summary (m228g <- felm (coupSuc ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m228h <- summary (m228h <- felm (coupSuc ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m228i <- summary (m228i <- felm (coupSuc ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m228j <- summary (m228j <- felm (coupSuc ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))


## (2.9) 2x9 models: failed coup during the year

# Growth only: 209 models
(sum.m209a <- summary (m209a <- felm (coupFail ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m209b <- summary (m209b <- felm (coupFail ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Actual elections: 219 models
(sum.m219a <- summary (m219a <- felm (coupFail ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m219b <- summary (m219b <- felm (coupFail ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m219c <- summary (m219c <- felm (coupFail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m219d <- summary (m219d <- felm (coupFail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m219e <- summary (m219e <- felm (coupFail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m219f <- summary (m219f <- felm (coupFail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m219f2 <- summary (m219f2 <- felm (coupFail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m219g <- summary (m219g <- felm (coupFail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m219h <- summary (m219h <- felm (coupFail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m219i <- summary (m219i <- felm (coupFail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m219j <- summary (m219j <- felm (coupFail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Scheduled elections: 229 models
(sum.m229a <- summary (m229a <- felm (coupFail ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m229b <- summary (m229b <- felm (coupFail ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m229e <- summary (m229e <- felm (coupFail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m229f <- summary (m229f <- felm (coupFail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m229f2 <- summary (m229f2 <- felm (coupFail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m229g <- summary (m229g <- felm (coupFail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m229h <- summary (m229h <- felm (coupFail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m229i <- summary (m229i <- felm (coupFail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m229j <- summary (m229j <- felm (coupFail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))



### (3) Replicating the models reported in Tables A19-A28, and Figures A12-A21: Alternative specifications (3xx models)

## (3.1) 3x1 models: alternative brakdown dates

# Growth only: 301 models
(sum.m301a <- summary (m301a <- felm (fail2 ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))
(sum.m301b <- summary (m301b <- felm (fail2 ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))

# Actual elections: 311 models
(sum.m311a <- summary (m311a <- felm (fail2 ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))
(sum.m311b <- summary (m311b <- felm (fail2 ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))
(sum.m311c <- summary (m311c <- felm (fail2 ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))
(sum.m311d <- summary (m311d <- felm (fail2 ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))
(sum.m311e <- summary (m311e <- felm (fail2 ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))
(sum.m311f <- summary (m311f <- felm (fail2 ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))
(sum.m311f2 <- summary (m311f2 <- felm (fail2 ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag) & maddMain$dateFailPost==0,])))
(sum.m311g <- summary (m311g <- felm (fail2 ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))
(sum.m311h <- summary (m311h <- felm (fail2 ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))
(sum.m311i <- summary (m311i <- felm (fail2 ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))
(sum.m311j <- summary (m311j <- felm (fail2 ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))

# Scheduled elections: 321 models
(sum.m321a <- summary (m321a <- felm (fail2 ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))
(sum.m321b <- summary (m321b <- felm (fail2 ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))
(sum.m321e <- summary (m321e <- felm (fail2 ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))
(sum.m321f <- summary (m321f <- felm (fail2 ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))
(sum.m321f2 <- summary (m321f2 <- felm (fail2 ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag) & maddMain$dateFailPost==0,])))
(sum.m321g <- summary (m321g <- felm (fail2 ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))
(sum.m321h <- summary (m321h <- felm (fail2 ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))
(sum.m321i <- summary (m321i <- felm (fail2 ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))
(sum.m321j <- summary (m321j <- felm (fail2 ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[maddMain$dateFailPost==0,])))


## (3.2) 3x2 models: survival (cloglog)

# Growth only: 302 models
(sum.m302a <- summary (m302a <- glm (fail ~ madddGDPHead_lag + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m302a <- cluster.vcov (m302a, cluster = ~ idRegime)
(coef.m302a <- coeftest (m302a, vcov.m302a)[-grep ("year.f", row.names (sum.m302a$coef)),])
(sum.m302b <- summary (m302b <- glm (fail ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m302b <- cluster.vcov (m302b, cluster = ~ idRegime)
(coef.m302b <- coeftest (m302b, vcov.m302b)[-grep ("year.f", row.names (sum.m302b$coef)),])

# Actual elections: 312 models
(sum.m312a <- summary (m312a <- glm (fail ~ comE + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m312a <- cluster.vcov (m312a, cluster = ~ idRegime)
(coef.m312a <- coeftest (m312a, vcov.m312a)[-grep ("year.f", row.names (sum.m312a$coef)),])
(sum.m312b <- summary (m312b <- glm (fail ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m312b <- cluster.vcov (m312b, cluster = ~ idRegime)
(coef.m312b <- coeftest (m312b, vcov.m312b)[-grep ("year.f", row.names (sum.m312b$coef)),])

(sum.m312c <- summary (m312c <- glm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m312c <- cluster.vcov (m312c, cluster = ~ idRegime)
(coef.m312c <- coeftest (m312c, vcov.m312c)[-grep ("year.f", row.names (sum.m312c$coef)),])
(sum.m312d <- summary (m312d <- glm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m312d <- cluster.vcov (m312d, cluster = ~ idRegime)
(coef.m312d <- coeftest (m312d, vcov.m312d)[-grep ("year.f", row.names (sum.m312d$coef)),])

(sum.m312e <- summary (m312e <- glm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m312e <- cluster.vcov (m312e, cluster = ~ idRegime)
(coef.m312e <- coeftest (m312e, vcov.m312e)[-grep ("year.f", row.names (sum.m312e$coef)),])
(sum.m312f <- summary (m312f <- glm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m312f <- cluster.vcov (m312f, cluster = ~ idRegime)
(coef.m312f <- coeftest (m312f, vcov.m312f)[-grep ("year.f", row.names (sum.m312f$coef)),])
(sum.m312f2 <- summary (m312f2 <- glm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], family=binomial (link="cloglog"))))
vcov.m312f2 <- cluster.vcov (m312f2, cluster = ~ idRegime)
(coef.m312f2 <- coeftest (m312f2, vcov.m312f2)[-grep ("year.f", row.names (sum.m312f2$coef)),])

(sum.m312g <- summary (m312g <- glm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m312g <- cluster.vcov (m312g, cluster = ~ idRegime)
(coef.m312g <- coeftest (m312g, vcov.m312g)[-grep ("year.f", row.names (sum.m312g$coef)),])
(sum.m312h <- summary (m312h <- glm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m312h <- cluster.vcov (m312h, cluster = ~ idRegime)
(coef.m312h <- coeftest (m312h, vcov.m312h)[-grep ("year.f", row.names (sum.m312h$coef)),])

(sum.m312i <- summary (m312i <- glm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m312i <- cluster.vcov (m312i, cluster = ~ idRegime)
(coef.m312i <- coeftest (m312i, vcov.m312i)[-grep ("year.f", row.names (sum.m312i$coef)),])
(sum.m312j <- summary (m312j <- glm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m312j <- cluster.vcov (m312j, cluster = ~ idRegime)
(coef.m312j <- coeftest (m312j, vcov.m312j)[-grep ("year.f", row.names (sum.m312j$coef)),])

# Scheduled elections: 322 models
(sum.m322a <- summary (m322a <- glm (fail ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m322a <- cluster.vcov (m322a, cluster = ~ idRegime)
(coef.m322a <- coeftest (m322a, vcov.m322a)[-grep ("year.f", row.names (sum.m322a$coef)),])
(sum.m322b <- summary (m322b <- glm (fail ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m322b <- cluster.vcov (m322b, cluster = ~ idRegime)
(coef.m322b <- coeftest (m322b, vcov.m322b)[-grep ("year.f", row.names (sum.m322b$coef)),])

(sum.m322e <- summary (m322e <- glm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m322e <- cluster.vcov (m322e, cluster = ~ idRegime)
(coef.m322e <- coeftest (m322e, vcov.m322e)[-grep ("year.f", row.names (sum.m322e$coef)),])
(sum.m322f <- summary (m322f <- glm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log(oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m322f <- cluster.vcov (m322f, cluster = ~ idRegime)
(coef.m322f <- coeftest (m322f, vcov.m322f)[-grep ("year.f", row.names (sum.m322f$coef)),])
(sum.m322f2 <- summary (m322f2 <- glm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], family=binomial (link="cloglog"))))
vcov.m322f2 <- cluster.vcov (m322f2, cluster = ~ idRegime)
(coef.m322f2 <- coeftest (m322f2, vcov.m322f2)[-grep ("year.f", row.names (sum.m322f2$coef)),])

(sum.m322g <- summary (m322g <- glm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m322g <- cluster.vcov (m322g, cluster = ~ idRegime)
(coef.m322g <- coeftest (m322g, vcov.m322g)[-grep ("year.f", row.names (sum.m322g$coef)),])
(sum.m322h <- summary (m322h <- glm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log(oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m322h <- cluster.vcov (m322h, cluster = ~ idRegime)
(coef.m322h <- coeftest (m322h, vcov.m322h)[-grep ("year.f", row.names (sum.m322h$coef)),])

(sum.m322i <- summary (m322i <- glm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m322i <- cluster.vcov (m322i, cluster = ~ idRegime)
(coef.m322i <- coeftest (m322i, vcov.m322i)[-grep ("year.f", row.names (sum.m322i$coef)),])
(sum.m322j <- summary (m322j <- glm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log(oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="cloglog"))))
vcov.m322j <- cluster.vcov (m322j, cluster = ~ idRegime)
(coef.m322j <- coeftest (m322j, vcov.m322j)[-grep ("year.f", row.names (sum.m322j$coef)),])


## (3.3) 3x3 models: survival (probit, simple)

# Growth only: 303 models
(sum.m303a <- summary (m303a <- glm (fail ~ madddGDPHead_lag + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m303a <- cluster.vcov (m303a, cluster = ~ idRegime)
(coef.m303a <- coeftest (m303a, vcov.m303a)[-grep ("year.f", row.names (sum.m303a$coef)),])
(sum.m303b <- summary (m303b <- glm (fail ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m303b <- cluster.vcov (m303b, cluster = ~ idRegime)
(coef.m303b <- coeftest (m303b, vcov.m303b)[-grep ("year.f", row.names (sum.m303b$coef)),])

# Actual elections: 313 models
(sum.m313a <- summary (m313a <- glm (fail ~ comE + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m313a <- cluster.vcov (m313a, cluster = ~ idRegime)
(coef.m313a <- coeftest (m313a, vcov.m313a)[-grep ("year.f", row.names (sum.m313a$coef)),])
(sum.m313b <- summary (m313b <- glm (fail ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m313b <- cluster.vcov (m313b, cluster = ~ idRegime)
(coef.m313b <- coeftest (m313b, vcov.m313b)[-grep ("year.f", row.names (sum.m313b$coef)),])

(sum.m313c <- summary (m313c <- glm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m313c <- cluster.vcov (m313c, cluster = ~ idRegime)
(coef.m313c <- coeftest (m313c, vcov.m313c)[-grep ("year.f", row.names (sum.m313c$coef)),])
(sum.m313d <- summary (m313d <- glm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m313d <- cluster.vcov (m313d, cluster = ~ idRegime)
(coef.m313d <- coeftest (m313d, vcov.m313d)[-grep ("year.f", row.names (sum.m313d$coef)),])

(sum.m313e <- summary (m313e <- glm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m313e <- cluster.vcov (m313e, cluster = ~ idRegime)
(coef.m313e <- coeftest (m313e, vcov.m313e)[-grep ("year.f", row.names (sum.m313e$coef)),])
(sum.m313f <- summary (m313f <- glm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m313f <- cluster.vcov (m313f, cluster = ~ idRegime)
(coef.m313f <- coeftest (m313f, vcov.m313f)[-grep ("year.f", row.names (sum.m313f$coef)),])
(sum.m313f2 <- summary (m313f2 <- glm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], family=binomial (link="probit"))))
vcov.m313f2 <- cluster.vcov (m313f2, cluster = ~ idRegime)
(coef.m313f2 <- coeftest (m313f2, vcov.m313f2)[-grep ("year.f", row.names (sum.m313f2$coef)),])

(sum.m313g <- summary (m313g <- glm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m313g <- cluster.vcov (m313g, cluster = ~ idRegime)
(coef.m313g <- coeftest (m313g, vcov.m313g)[-grep ("year.f", row.names (sum.m313g$coef)),])
(sum.m313h <- summary (m313h <- glm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m313h <- cluster.vcov (m313h, cluster = ~ idRegime)
(coef.m313h <- coeftest (m313h, vcov.m313h)[-grep ("year.f", row.names (sum.m313h$coef)),])

(sum.m313i <- summary (m313i <- glm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m313i <- cluster.vcov (m313i, cluster = ~ idRegime)
(coef.m313i <- coeftest (m313i, vcov.m313i)[-grep ("year.f", row.names (sum.m313i$coef)),])
(sum.m313j <- summary (m313j <- glm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m313j <- cluster.vcov (m313j, cluster = ~ idRegime)
(coef.m313j <- coeftest (m313j, vcov.m313j)[-grep ("year.f", row.names (sum.m313j$coef)),])

# Scheduled elections: 323 models
(sum.m323a <- summary (m323a <- glm (fail ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m323a <- cluster.vcov (m323a, cluster = ~ idRegime)
(coef.m323a <- coeftest (m323a, vcov.m323a)[-grep ("year.f", row.names (sum.m323a$coef)),])
(sum.m323b <- summary (m323b <- glm (fail ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m323b <- cluster.vcov (m323b, cluster = ~ idRegime)
(coef.m323b <- coeftest (m323b, vcov.m323b)[-grep ("year.f", row.names (sum.m323b$coef)),])

(sum.m323e <- summary (m323e <- glm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m323e <- cluster.vcov (m323e, cluster = ~ idRegime)
(coef.m323e <- coeftest (m323e, vcov.m323e)[-grep ("year.f", row.names (sum.m323e$coef)),])
(sum.m323f <- summary (m323f <- glm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log(oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m323f <- cluster.vcov (m323f, cluster = ~ idRegime)
(coef.m323f <- coeftest (m323f, vcov.m323f)[-grep ("year.f", row.names (sum.m323f$coef)),])
(sum.m323f2 <- summary (m323f2 <- glm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], family=binomial (link="probit"))))
vcov.m323f2 <- cluster.vcov (m323f2, cluster = ~ idRegime)
(coef.m323f2 <- coeftest (m323f2, vcov.m323f2)[-grep ("year.f", row.names (sum.m323f2$coef)),])

(sum.m323g <- summary (m323g <- glm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m323g <- cluster.vcov (m323g, cluster = ~ idRegime)
(coef.m323g <- coeftest (m323g, vcov.m323g)[-grep ("year.f", row.names (sum.m323g$coef)),])
(sum.m323h <- summary (m323h <- glm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log(oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m323h <- cluster.vcov (m323h, cluster = ~ idRegime)
(coef.m323h <- coeftest (m323h, vcov.m323h)[-grep ("year.f", row.names (sum.m323h$coef)),])

(sum.m323i <- summary (m323i <- glm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m323i <- cluster.vcov (m323i, cluster = ~ idRegime)
(coef.m323i <- coeftest (m323i, vcov.m323i)[-grep ("year.f", row.names (sum.m323i$coef)),])
(sum.m323j <- summary (m323j <- glm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log(oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m323j <- cluster.vcov (m323j, cluster = ~ idRegime)
(coef.m323j <- coeftest (m323j, vcov.m323j)[-grep ("year.f", row.names (sum.m323j$coef)),])


## (3.4) 3x4 models: survival (probit, unit means)

# Growth only: 304 models
(sum.m304a <- summary (m304a <- glm (fail ~ madddGDPHead_lag + log(maddGDPHead_lag) + madddGDPHead_lag_mean + maddGDPHead_lag_log_mean + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m304a <- cluster.vcov (m304a, cluster = ~ idRegime)
(coef.m304a <- coeftest (m304a, vcov.m304a)[-grep ("year.f", row.names (sum.m304a$coef)),])
(sum.m304b <- summary (m304b <- glm (fail ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + madddGDPHead_lag_mean2 + maddGDPHead_lag_log_mean2 + oil_gas_valuePOP_2000_lag_log_mean2 + propDemo_mean2 + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m304b <- cluster.vcov (m304b, cluster = ~ idRegime)
(coef.m304b <- coeftest (m304b, vcov.m304b)[-grep ("year.f", row.names (sum.m304b$coef)),])

# Actual elections: 314 models
(sum.m314a <- summary (m314a <- glm (fail ~ comE + log(maddGDPHead_lag) + comE_mean + maddGDPHead_lag_log_mean + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m314a <- cluster.vcov (m314a, cluster = ~ idRegime)
(coef.m314a <- coeftest (m314a, vcov.m314a)[-grep ("year.f", row.names (sum.m314a$coef)),])
(sum.m314b <- summary (m314b <- glm (fail ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + comE_mean2 + maddGDPHead_lag_log_mean2 + oil_gas_valuePOP_2000_lag_log_mean2 + propDemo_mean2 + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m314b <- cluster.vcov (m314b, cluster = ~ idRegime)
(coef.m314b <- coeftest (m314b, vcov.m314b)[-grep ("year.f", row.names (sum.m314b$coef)),])

(sum.m314c <- summary (m314c <- glm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + madddGDPHead_lag_mean + comE_mean + madddGDPHead_lag_comE_mean + maddGDPHead_lag_log_mean + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m314c <- cluster.vcov (m314c, cluster = ~ idRegime)
(coef.m314c <- coeftest (m314c, vcov.m314c)[-grep ("year.f", row.names (sum.m314c$coef)),])
(sum.m314d <- summary (m314d <- glm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + madddGDPHead_lag_mean2 + comE_mean2 + madddGDPHead_lag_comE_mean2 + maddGDPHead_lag_log_mean2 + oil_gas_valuePOP_2000_lag_log_mean2 + propDemo_mean2 + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m314d <- cluster.vcov (m314d, cluster = ~ idRegime)
(coef.m314d <- coeftest (m314d, vcov.m314d)[-grep ("year.f", row.names (sum.m314d$coef)),])

(sum.m314e <- summary (m314e <- glm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + madddGDPHead_lag_mean + comE_mean + madddGDPHead_lag_comE_mean + madddGDPHead_lag_ear_mean + madddGDPHead_lag_comE_ear_mean + ear_mean + comE_ear_mean + maddGDPHead_lag_log_mean + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m314e <- cluster.vcov (m314e, cluster = ~ idRegime)
(coef.m314e <- coeftest (m314e, vcov.m314e)[-grep ("year.f", row.names (sum.m314e$coef)),])
(sum.m314f <- summary (m314f <- glm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + madddGDPHead_lag_mean2 + comE_mean2 + madddGDPHead_lag_comE_mean2 + madddGDPHead_lag_ear_mean2 + madddGDPHead_lag_comE_ear_mean2 + ear_mean2 + comE_ear_mean2 + maddGDPHead_lag_log_mean2 + oil_gas_valuePOP_2000_lag_log_mean2 + propDemo_mean2 + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m314f <- cluster.vcov (m314f, cluster = ~ idRegime)
(coef.m314f <- coeftest (m314f, vcov.m314f)[-grep ("year.f", row.names (sum.m314f$coef)),])
(sum.m314f2 <- summary (m314f2 <- glm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + madddGDPHead_lag_mean2 + comE_mean2 + madddGDPHead_lag_comE_mean2 + madddGDPHead_lag_ear_mean2 + madddGDPHead_lag_comE_ear_mean2 + ear_mean2 + comE_ear_mean2 + maddGDPHead_lag_log_mean2 + propDemo_mean2 + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], family=binomial (link="probit"))))
vcov.m314f2 <- cluster.vcov (m314f2, cluster = ~ idRegime)
(coef.m314f2 <- coeftest (m314f2, vcov.m314f2)[-grep ("year.f", row.names (sum.m314f2$coef)),])

(sum.m314g <- summary (m314g <- glm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + madddGDPHead_lag_mean + nocomE_mean + madddGDPHead_lag_nocomE_mean + madddGDPHead_lag_earNoComp_mean + madddGDPHead_lag_nocomE_earNoComp_mean + earNoComp_mean + nocomE_earNoComp_mean + maddGDPHead_lag_log_mean + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m314g <- cluster.vcov (m314g, cluster = ~ idRegime)
(coef.m314g <- coeftest (m314g, vcov.m314g)[-grep ("year.f", row.names (sum.m314g$coef)),])
(sum.m314h <- summary (m314h <- glm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + madddGDPHead_lag_mean2 + nocomE_mean2 + madddGDPHead_lag_nocomE_mean2 + madddGDPHead_lag_earNoComp_mean2 + madddGDPHead_lag_nocomE_earNoComp_mean2 + earNoComp_mean2 + nocomE_earNoComp_mean2 + maddGDPHead_lag_log_mean2 + oil_gas_valuePOP_2000_lag_log_mean2 + propDemo_mean2 + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m314h <- cluster.vcov (m314h, cluster = ~ idRegime)
(coef.m314h <- coeftest (m314h, vcov.m314h)[-grep ("year.f", row.names (sum.m314h$coef)),])

(sum.m314i <- summary (m314i <- glm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + madddGDPHead_lag_mean + comL2_mean + madddGDPHead_lag_comL2_mean + madddGDPHead_lag_ear_mean + madddGDPHead_lag_comL2_ear_mean + ear_mean + comL2_ear_mean + maddGDPHead_lag_log_mean + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m314i <- cluster.vcov (m314i, cluster = ~ idRegime)
(coef.m314i <- coeftest (m314i, vcov.m314i)[-grep ("year.f", row.names (sum.m314i$coef)),])
(sum.m314j <- summary (m314j <- glm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + madddGDPHead_lag_mean2 + comL2_mean2 + madddGDPHead_lag_comL2_mean2 + madddGDPHead_lag_ear_mean2 + madddGDPHead_lag_comL2_ear_mean2 + ear_mean2 + comL2_ear_mean2 + maddGDPHead_lag_log_mean2 + oil_gas_valuePOP_2000_lag_log_mean2 + propDemo_mean2 + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m314j <- cluster.vcov (m314j, cluster = ~ idRegime)
(coef.m314j <- coeftest (m314j, vcov.m314j)[-grep ("year.f", row.names (sum.m314j$coef)),])

# Scheduled elections: 324 models
(sum.m324a <- summary (m324a <- glm (fail ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + yComEfThis_year_mean + yComEfOther_year_mean + maddGDPHead_lag_log_mean + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m324a <- cluster.vcov (m324a, cluster = ~ idRegime)
(coef.m324a <- coeftest (m324a, vcov.m324a)[-grep ("year.f", row.names (sum.m324a$coef)),])
(sum.m324b <- summary (m324b <- glm (fail ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + yComEfThis_year_mean2 + yComEfOther_year_mean2 + maddGDPHead_lag_log_mean2 + oil_gas_valuePOP_2000_lag_log_mean2 + propDemo_mean2 + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m324b <- cluster.vcov (m324b, cluster = ~ idRegime)
(coef.m324b <- coeftest (m324b, vcov.m324b)[-grep ("year.f", row.names (sum.m324b$coef)),])

(sum.m324e <- summary (m324e <- glm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + madddGDPHead_lag_mean + yComEfThis_year_mean + yComEfOther_year_mean + madddGDPHead_lag_yComEfThis_year_mean + madddGDPHead_lag_yComEfOther_year_mean + maddGDPHead_lag_log_mean + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m324e <- cluster.vcov (m324e, cluster = ~ idRegime)
(coef.m324e <- coeftest (m324e, vcov.m324e)[-grep ("year.f", row.names (sum.m324e$coef)),])
(sum.m324f <- summary (m324f <- glm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log(oil_gas_valuePOP_2000_lag+1) + propDemo + madddGDPHead_lag_mean2 + yComEfThis_year_mean2 + yComEfOther_year_mean2 + madddGDPHead_lag_yComEfThis_year_mean2 + madddGDPHead_lag_yComEfOther_year_mean2 + maddGDPHead_lag_log_mean2 + oil_gas_valuePOP_2000_lag_log_mean2 + propDemo_mean2 + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m324f <- cluster.vcov (m324f, cluster = ~ idRegime)
(coef.m324f <- coeftest (m324f, vcov.m324f)[-grep ("year.f", row.names (sum.m324f$coef)),])
(sum.m324f2 <- summary (m324f2 <- glm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + madddGDPHead_lag_mean2 + yComEfThis_year_mean2 + yComEfOther_year_mean2 + madddGDPHead_lag_yComEfThis_year_mean2 + madddGDPHead_lag_yComEfOther_year_mean2 + maddGDPHead_lag_log_mean2 + propDemo_mean2 + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),], family=binomial (link="probit"))))
vcov.m324f2 <- cluster.vcov (m324f2, cluster = ~ idRegime)
(coef.m324f2 <- coeftest (m324f2, vcov.m324f2)[-grep ("year.f", row.names (sum.m324f2$coef)),])

(sum.m324g <- summary (m324g <- glm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + madddGDPHead_lag_mean + ynoComEfThis_year_mean + ynoComEfOther_year_mean + madddGDPHead_lag_ynoComEfThis_year_mean + madddGDPHead_lag_ynoComEfOther_year_mean + maddGDPHead_lag_log_mean + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m324g <- cluster.vcov (m324g, cluster = ~ idRegime)
(coef.m324g <- coeftest (m324g, vcov.m324g)[-grep ("year.f", row.names (sum.m324g$coef)),])
(sum.m324h <- summary (m324h <- glm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log(oil_gas_valuePOP_2000_lag+1) + propDemo + madddGDPHead_lag_mean2 + ynoComEfThis_year_mean2 + ynoComEfOther_year_mean2 + madddGDPHead_lag_ynoComEfThis_year_mean2 + madddGDPHead_lag_ynoComEfOther_year_mean2 + maddGDPHead_lag_log_mean2 + oil_gas_valuePOP_2000_lag_log_mean2 + propDemo_mean2 + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m324h <- cluster.vcov (m324h, cluster = ~ idRegime)
(coef.m324h <- coeftest (m324h, vcov.m324h)[-grep ("year.f", row.names (sum.m324h$coef)),])

(sum.m324i <- summary (m324i <- glm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + madddGDPHead_lag_mean + yComOnlyLfThis_year_mean + yComOnlyLfOther_year_mean + madddGDPHead_lag_yComOnlyLfThis_year_mean + madddGDPHead_lag_yComOnlyLfOther_year_mean + yComOnlyLfThis_year_both_mean + madddGDPHead_lag_yComOnlyLfThis_year_both_mean + maddGDPHead_lag_log_mean + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m324i <- cluster.vcov (m324i, cluster = ~ idRegime)
(coef.m324i <- coeftest (m324i, vcov.m324i)[-grep ("year.f", row.names (sum.m324i$coef)),])
(sum.m324j <- summary (m324j <- glm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log(oil_gas_valuePOP_2000_lag+1) + propDemo + madddGDPHead_lag_mean2 + yComOnlyLfThis_year_mean2 + yComOnlyLfOther_year_mean2 + madddGDPHead_lag_yComOnlyLfThis_year_mean2 + madddGDPHead_lag_yComOnlyLfOther_year_mean2 + yComOnlyLfThis_year_both_mean2 + madddGDPHead_lag_yComOnlyLfThis_year_both_mean2 + maddGDPHead_lag_log_mean2 + oil_gas_valuePOP_2000_lag_log_mean2 + propDemo_mean2 + party2 + military2 + personal2 + year.f + region + poly (duration, 3) -1, data=maddMain, family=binomial (link="probit"))))
vcov.m324j <- cluster.vcov (m324j, cluster = ~ idRegime)
(coef.m324j <- coeftest (m324j, vcov.m324j)[-grep ("year.f", row.names (sum.m324j$coef)),])


## (3.5) 3x5 models: country FEs

# Growth only: 305 models
(sum.m305a <- summary (m305a <- felm (fail ~ madddGDPHead_lag + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))
(sum.m305b <- summary (m305b <- felm (fail ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))

# Actual elections: 315 models
(sum.m315a <- summary (m315a <- felm (fail ~ comE + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))
(sum.m315b <- summary (m315b <- felm (fail ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))
(sum.m315c <- summary (m315c <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))
(sum.m315d <- summary (m315d <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))
(sum.m315e <- summary (m315e <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))
(sum.m315f <- summary (m315f <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))
(sum.m315f2 <- summary (m315f2 <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | country + year.f | 0 | country, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m315g <- summary (m315g <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))
(sum.m315h <- summary (m315h <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))
(sum.m315i <- summary (m315i <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))
(sum.m315j <- summary (m315j <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))

# Scheduled elections: 325 models
(sum.m325a <- summary (m325a <- felm (fail ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))
(sum.m325b <- summary (m325b <- felm (fail ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))
(sum.m325e <- summary (m325e <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))
(sum.m325f <- summary (m325f <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))
(sum.m325f2 <- summary (m325f2 <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | country + year.f | 0 | country, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m325g <- summary (m325g <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))
(sum.m325h <- summary (m325h <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))
(sum.m325i <- summary (m325i <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))
(sum.m325j <- summary (m325j <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | country + year.f | 0 | country, data=maddMain)))



### (4) Replicating the models reported in Tables A29-A31 and Figures A22-A24: Alternative measures of regime type (4xx models)

## (4.1) 4x1 models: including indirect regimes and oligarchies

# Growth only: 401 models
(sum.m401a <- summary (m401a <- felm (fail ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))
(sum.m401b <- summary (m401b <- felm (fail ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))

# Actual elections: 411 models
(sum.m411a <- summary (m411a <- felm (fail ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))
(sum.m411b <- summary (m411b <- felm (fail ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))
(sum.m411c <- summary (m411c <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))
(sum.m411d <- summary (m411d <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))
(sum.m411e <- summary (m411e <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))
(sum.m411f <- summary (m411f <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))
(sum.m411f2 <- summary (m411f2 <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2[!is.na (maddMain2$oil_gas_valuePOP_2000_lag),])))
(sum.m411g <- summary (m411g <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))
(sum.m411h <- summary (m411h <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))
(sum.m411i <- summary (m411i <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))
(sum.m411j <- summary (m411j <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))

# Scheduled elections: 421 models
(sum.m421a <- summary (m421a <- felm (fail ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))
(sum.m421b <- summary (m421b <- felm (fail ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))
(sum.m421e <- summary (m421e <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))
(sum.m421f <- summary (m421f <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))
(sum.m421f2 <- summary (m421f2 <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2[!is.na (maddMain2$oil_gas_valuePOP_2000_lag),])))
(sum.m421g <- summary (m421g <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))
(sum.m421h <- summary (m421h <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))
(sum.m421i <- summary (m421i <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))
(sum.m421j <- summary (m421j <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2)))


## (4.2) 4x2 models: LIED coding of EARs and closed regimes

# Growth only: 402 models
(sum.m402a <- summary (m402a <- felm (fail ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))
(sum.m402b <- summary (m402b <- felm (fail ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))

# Actual elections: 412 models
(sum.m412a <- summary (m412a <- felm (fail ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))
(sum.m412b <- summary (m412b <- felm (fail ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))
(sum.m412c <- summary (m412c <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))
(sum.m412d <- summary (m412d <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))
(sum.m412e <- summary (m412e <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*earLIED) + I(madddGDPHead_lag*comE*earLIED) + earLIED + I(comE*earLIED) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))
(sum.m412f <- summary (m412f <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*earLIED) + I(madddGDPHead_lag*comE*earLIED) + earLIED + I(comE*earLIED) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))
(sum.m412f2 <- summary (m412f2 <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*earLIED) + earLIED + I(comE*earLIED) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied[!is.na (maddMain2lied$oil_gas_valuePOP_2000_lag),])))
(sum.m412g <- summary (m412g <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoCompLIED) + I(madddGDPHead_lag*nocomE*earNoCompLIED) + earNoCompLIED + I(nocomE*earNoCompLIED) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))
(sum.m412h <- summary (m412h <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoCompLIED) + I(madddGDPHead_lag*nocomE*earNoCompLIED) + earNoCompLIED + I(nocomE*earNoCompLIED) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))
(sum.m412i <- summary (m412i <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*earLIED) + I(madddGDPHead_lag*comL2*earLIED) + earLIED + I(comL2*earLIED) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))
(sum.m412j <- summary (m412j <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*earLIED) + I(madddGDPHead_lag*comL2*earLIED) + earLIED + I(comL2*earLIED) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))

# Scheduled elections: 422 models
(sum.m422a <- summary (m422a <- felm (fail ~ yComEfThis_yearlied + yComEfOther_yearlied + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))
(sum.m422b <- summary (m422b <- felm (fail ~ yComEfThis_yearlied + yComEfOther_yearlied + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))
(sum.m422e <- summary (m422e <- felm (fail ~ madddGDPHead_lag + yComEfThis_yearlied + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_yearlied) + I(madddGDPHead_lag*yComEfOther_yearlied) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))
(sum.m422f <- summary (m422f <- felm (fail ~ madddGDPHead_lag + yComEfThis_yearlied + yComEfOther_yearlied + I(madddGDPHead_lag*yComEfThis_yearlied) + I(madddGDPHead_lag*yComEfOther_yearlied) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))
(sum.m422f2 <- summary (m422f2 <- felm (fail ~ madddGDPHead_lag + yComEfThis_yearlied + yComEfOther_yearlied + I(madddGDPHead_lag*yComEfThis_yearlied) + I(madddGDPHead_lag*yComEfOther_yearlied) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied[!is.na (maddMain2lied$oil_gas_valuePOP_2000_lag),])))
(sum.m422g <- summary (m422g <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_yearlied + ynoComEfOther_yearlied + I(madddGDPHead_lag*ynoComEfThis_yearlied) + I(madddGDPHead_lag*ynoComEfOther_yearlied) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))
(sum.m422h <- summary (m422h <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_yearlied + ynoComEfOther_yearlied + I(madddGDPHead_lag*ynoComEfThis_yearlied) + I(madddGDPHead_lag*ynoComEfOther_yearlied) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))
(sum.m422i <- summary (m422i <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_yearlied + yComOnlyLfOther_yearlied + I(madddGDPHead_lag*yComOnlyLfThis_yearlied) + I(madddGDPHead_lag*yComOnlyLfOther_yearlied) + yComOnlyLfThis_year_bothlied + I(madddGDPHead_lag*yComOnlyLfThis_year_bothlied) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))
(sum.m422j <- summary (m422j <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_yearlied + yComOnlyLfOther_yearlied + I(madddGDPHead_lag*yComOnlyLfThis_yearlied) + I(madddGDPHead_lag*yComOnlyLfOther_yearlied) + yComOnlyLfThis_year_bothlied + I(madddGDPHead_lag*yComOnlyLfThis_year_bothlied) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2lied)))


## (4.3) 4x3 models: V-Dem coding of EARs and closed regimes

# Growth only: 403 models
(sum.m403a <- summary (m403a <- felm (fail ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))
(sum.m403b <- summary (m403b <- felm (fail ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))

# Actual elections: 413 models
(sum.m413a <- summary (m413a <- felm (fail ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))
(sum.m413b <- summary (m413b <- felm (fail ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))
(sum.m413c <- summary (m413c <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))
(sum.m413d <- summary (m413d <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))
(sum.m413e <- summary (m413e <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*earVDem) + I(madddGDPHead_lag*comE*earVDem) + earVDem + I(comE*earVDem) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))
(sum.m413f <- summary (m413f <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*earVDem) + I(madddGDPHead_lag*comE*earVDem) + earVDem + I(comE*earVDem) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))
(sum.m413f2 <- summary (m413f2 <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*earVDem) + earVDem + I(comE*earVDem) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem[!is.na (maddMain2vdem$oil_gas_valuePOP_2000_lag),])))
(sum.m413g <- summary (m413g <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoCompVDem) + I(madddGDPHead_lag*nocomE*earNoCompVDem) + earNoCompVDem + I(nocomE*earNoCompVDem) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))
(sum.m413h <- summary (m413h <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoCompVDem) + I(madddGDPHead_lag*nocomE*earNoCompVDem) + earNoCompVDem + I(nocomE*earNoCompVDem) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))
(sum.m413i <- summary (m413i <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*earVDem) + I(madddGDPHead_lag*comL2*earVDem) + earVDem + I(comL2*earVDem) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))
(sum.m413j <- summary (m413j <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*earVDem) + I(madddGDPHead_lag*comL2*earVDem) + earVDem + I(comL2*earVDem) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))

# Scheduled elections: 423 models
(sum.m423a <- summary (m423a <- felm (fail ~ yComEfThis_yearvdem + yComEfOther_yearvdem + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))
(sum.m423b <- summary (m423b <- felm (fail ~ yComEfThis_yearvdem + yComEfOther_yearvdem + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))
(sum.m423e <- summary (m423e <- felm (fail ~ madddGDPHead_lag + yComEfThis_yearvdem + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_yearvdem) + I(madddGDPHead_lag*yComEfOther_yearvdem) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))
(sum.m423f <- summary (m423f <- felm (fail ~ madddGDPHead_lag + yComEfThis_yearvdem + yComEfOther_yearvdem + I(madddGDPHead_lag*yComEfThis_yearvdem) + I(madddGDPHead_lag*yComEfOther_yearvdem) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))
(sum.m423f2 <- summary (m423f2 <- felm (fail ~ madddGDPHead_lag + yComEfThis_yearvdem + yComEfOther_yearvdem + I(madddGDPHead_lag*yComEfThis_yearvdem) + I(madddGDPHead_lag*yComEfOther_yearvdem) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem[!is.na (maddMain2vdem$oil_gas_valuePOP_2000_lag),])))
(sum.m423g <- summary (m423g <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_yearvdem + ynoComEfOther_yearvdem + I(madddGDPHead_lag*ynoComEfThis_yearvdem) + I(madddGDPHead_lag*ynoComEfOther_yearvdem) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))
(sum.m423h <- summary (m423h <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_yearvdem + ynoComEfOther_yearvdem + I(madddGDPHead_lag*ynoComEfThis_yearvdem) + I(madddGDPHead_lag*ynoComEfOther_yearvdem) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))
(sum.m423i <- summary (m423i <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_yearvdem + yComOnlyLfOther_yearvdem + I(madddGDPHead_lag*yComOnlyLfThis_yearvdem) + I(madddGDPHead_lag*yComOnlyLfOther_yearvdem) + yComOnlyLfThis_year_bothvdem + I(madddGDPHead_lag*yComOnlyLfThis_year_bothvdem) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))
(sum.m423j <- summary (m423j <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_yearvdem + yComOnlyLfOther_yearvdem + I(madddGDPHead_lag*yComOnlyLfThis_yearvdem) + I(madddGDPHead_lag*yComOnlyLfOther_yearvdem) + yComOnlyLfThis_year_bothvdem + I(madddGDPHead_lag*yComOnlyLfThis_year_bothvdem) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain2vdem)))



### (5) Replicating the models reported in Tables A32-A34 and Figures A25-A27: Alternative measures of economic performance (5xx models)

## (5.1) 5x1 models: recession dummy (growth rate below -5.0%)

# Growth only: 501 models
(sum.m501a <- summary (m501a <- felm (fail ~ maddRec50_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m501b <- summary (m501b <- felm (fail ~ maddRec50_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Actual elections: 511 models
(sum.m511a <- summary (m511a <- felm (fail ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m511b <- summary (m511b <- felm (fail ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m511c <- summary (m511c <- felm (fail ~ maddRec50_lag + comE + I(maddRec50_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m511d <- summary (m511d <- felm (fail ~ maddRec50_lag + comE + I(maddRec50_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m511e <- summary (m511e <- felm (fail ~ maddRec50_lag + comE + I(maddRec50_lag*comE) + I(maddRec50_lag*ear) + I(maddRec50_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m511f <- summary (m511f <- felm (fail ~ maddRec50_lag + comE + I(maddRec50_lag*comE) + I(maddRec50_lag*ear) + I(maddRec50_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m511f2 <- summary (m511f2 <- felm (fail ~ maddRec50_lag + comE + I(maddRec50_lag*comE) + I(maddRec50_lag*ear) + I(maddRec50_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m511g <- summary (m511g <- felm (fail ~ maddRec50_lag + nocomE + I(maddRec50_lag*nocomE) + I(maddRec50_lag*earNoComp) + I(maddRec50_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m511h <- summary (m511h <- felm (fail ~ maddRec50_lag + nocomE + I(maddRec50_lag*nocomE) + I(maddRec50_lag*earNoComp) + I(maddRec50_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m511i <- summary (m511i <- felm (fail ~ maddRec50_lag + comL2 + I(maddRec50_lag*comL2) + I(maddRec50_lag*ear) + I(maddRec50_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m511j <- summary (m511j <- felm (fail ~ maddRec50_lag + comL2 + I(maddRec50_lag*comL2) + I(maddRec50_lag*ear) + I(maddRec50_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))

# Scheduled elections: 521 models
(sum.m521a <- summary (m521a <- felm (fail ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m521b <- summary (m521b <- felm (fail ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m521e <- summary (m521e <- felm (fail ~ maddRec50_lag + yComEfThis_year + yComEfOther_year + I(maddRec50_lag*yComEfThis_year) + I(maddRec50_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m521f <- summary (m521f <- felm (fail ~ maddRec50_lag + yComEfThis_year + yComEfOther_year + I(maddRec50_lag*yComEfThis_year) + I(maddRec50_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m521f2 <- summary (m521f2 <- felm (fail ~ maddRec50_lag + yComEfThis_year + yComEfOther_year + I(maddRec50_lag*yComEfThis_year) + I(maddRec50_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m521g <- summary (m521g <- felm (fail ~ maddRec50_lag + ynoComEfThis_year + ynoComEfOther_year + I(maddRec50_lag*ynoComEfThis_year) + I(maddRec50_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m521h <- summary (m521h <- felm (fail ~ maddRec50_lag + ynoComEfThis_year + ynoComEfOther_year + I(maddRec50_lag*ynoComEfThis_year) + I(maddRec50_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m521i <- summary (m521i <- felm (fail ~ maddRec50_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(maddRec50_lag*yComOnlyLfThis_year) + I(maddRec50_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(maddRec50_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))
(sum.m521j <- summary (m521j <- felm (fail ~ maddRec50_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(maddRec50_lag*yComOnlyLfThis_year) + I(maddRec50_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(maddRec50_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=maddMain)))


## (5.2) 5x2 models: PWT 9.0 data

# Growth only: 502 models
(sum.m502a <- summary (m502a <- felm (fail ~ pwtdGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))
(sum.m502b <- summary (m502b <- felm (fail ~ pwtdGDPHead_lag + log(pwtGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))

# Actual elections: 512 models
(sum.m512a <- summary (m512a <- felm (fail ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))
(sum.m512b <- summary (m512b <- felm (fail ~ comE + log(pwtGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))
(sum.m512c <- summary (m512c <- felm (fail ~ pwtdGDPHead_lag + comE + I(pwtdGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))
(sum.m512d <- summary (m512d <- felm (fail ~ pwtdGDPHead_lag + comE + I(pwtdGDPHead_lag*comE) + log(pwtGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))
(sum.m512e <- summary (m512e <- felm (fail ~ pwtdGDPHead_lag + comE + I(pwtdGDPHead_lag*comE) + I(pwtdGDPHead_lag*ear) + I(pwtdGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))
(sum.m512f <- summary (m512f <- felm (fail ~ pwtdGDPHead_lag + comE + I(pwtdGDPHead_lag*comE) + I(pwtdGDPHead_lag*ear) + I(pwtdGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(pwtGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))
(sum.m512f2 <- summary (m512f2 <- felm (fail ~ pwtdGDPHead_lag + comE + I(pwtdGDPHead_lag*comE) + I(pwtdGDPHead_lag*ear) + I(pwtdGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(pwtGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain[!is.na (pwtMain$oil_gas_valuePOP_2000_lag),])))
(sum.m512g <- summary (m512g <- felm (fail ~ pwtdGDPHead_lag + nocomE + I(pwtdGDPHead_lag*nocomE) + I(pwtdGDPHead_lag*earNoComp) + I(pwtdGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))
(sum.m512h <- summary (m512h <- felm (fail ~ pwtdGDPHead_lag + nocomE + I(pwtdGDPHead_lag*nocomE) + I(pwtdGDPHead_lag*earNoComp) + I(pwtdGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(pwtGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))
(sum.m512i <- summary (m512i <- felm (fail ~ pwtdGDPHead_lag + comL2 + I(pwtdGDPHead_lag*comL2) + I(pwtdGDPHead_lag*ear) + I(pwtdGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))
(sum.m512j <- summary (m512j <- felm (fail ~ pwtdGDPHead_lag + comL2 + I(pwtdGDPHead_lag*comL2) + I(pwtdGDPHead_lag*ear) + I(pwtdGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(pwtGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))

# Scheduled elections: 522 models
(sum.m522a <- summary (m522a <- felm (fail ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))
(sum.m522b <- summary (m522b <- felm (fail ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))
(sum.m522e <- summary (m522e <- felm (fail ~ pwtdGDPHead_lag + yComEfThis_year + yComEfOther_year + I(pwtdGDPHead_lag*yComEfThis_year) + I(pwtdGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))
(sum.m522f <- summary (m522f <- felm (fail ~ pwtdGDPHead_lag + yComEfThis_year + yComEfOther_year + I(pwtdGDPHead_lag*yComEfThis_year) + I(pwtdGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))
(sum.m522f2 <- summary (m522f2 <- felm (fail ~ pwtdGDPHead_lag + yComEfThis_year + yComEfOther_year + I(pwtdGDPHead_lag*yComEfThis_year) + I(pwtdGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain[!is.na (pwtMain$oil_gas_valuePOP_2000_lag),])))
(sum.m522g <- summary (m522g <- felm (fail ~ pwtdGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(pwtdGDPHead_lag*ynoComEfThis_year) + I(pwtdGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))
(sum.m522h <- summary (m522h <- felm (fail ~ pwtdGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(pwtdGDPHead_lag*ynoComEfThis_year) + I(pwtdGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))
(sum.m522i <- summary (m522i <- felm (fail ~ pwtdGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(pwtdGDPHead_lag*yComOnlyLfThis_year) + I(pwtdGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(pwtdGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))
(sum.m522j <- summary (m522j <- felm (fail ~ pwtdGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(pwtdGDPHead_lag*yComOnlyLfThis_year) + I(pwtdGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(pwtdGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=pwtMain)))


## (5.3) 5x3 models: WDI data

# Growth only: 503 models
(sum.m503a <- summary (m503a <- felm (fail ~ wdidGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))
(sum.m503b <- summary (m503b <- felm (fail ~ wdidGDPHead_lag + log(wdiGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))

# Actual elections: 513 models
(sum.m513a <- summary (m513a <- felm (fail ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))
(sum.m513b <- summary (m513b <- felm (fail ~ comE + log(wdiGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))
(sum.m513c <- summary (m513c <- felm (fail ~ wdidGDPHead_lag + comE + I(wdidGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))
(sum.m513d <- summary (m513d <- felm (fail ~ wdidGDPHead_lag + comE + I(wdidGDPHead_lag*comE) + log(wdiGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))
(sum.m513e <- summary (m513e <- felm (fail ~ wdidGDPHead_lag + comE + I(wdidGDPHead_lag*comE) + I(wdidGDPHead_lag*ear) + I(wdidGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))
(sum.m513f <- summary (m513f <- felm (fail ~ wdidGDPHead_lag + comE + I(wdidGDPHead_lag*comE) + I(wdidGDPHead_lag*ear) + I(wdidGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(wdiGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))
(sum.m513f2 <- summary (m513f2 <- felm (fail ~ wdidGDPHead_lag + comE + I(wdidGDPHead_lag*comE) + I(wdidGDPHead_lag*ear) + I(wdidGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(wdiGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain[!is.na (wdiMain$oil_gas_valuePOP_2000_lag),])))
(sum.m513g <- summary (m513g <- felm (fail ~ wdidGDPHead_lag + nocomE + I(wdidGDPHead_lag*nocomE) + I(wdidGDPHead_lag*earNoComp) + I(wdidGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))
(sum.m513h <- summary (m513h <- felm (fail ~ wdidGDPHead_lag + nocomE + I(wdidGDPHead_lag*nocomE) + I(wdidGDPHead_lag*earNoComp) + I(wdidGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(wdiGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))
(sum.m513i <- summary (m513i <- felm (fail ~ wdidGDPHead_lag + comL2 + I(wdidGDPHead_lag*comL2) + I(wdidGDPHead_lag*ear) + I(wdidGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))
(sum.m513j <- summary (m513j <- felm (fail ~ wdidGDPHead_lag + comL2 + I(wdidGDPHead_lag*comL2) + I(wdidGDPHead_lag*ear) + I(wdidGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(wdiGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))

# Scheduled elections: 523 models
(sum.m523a <- summary (m523a <- felm (fail ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))
(sum.m523b <- summary (m523b <- felm (fail ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))
(sum.m523e <- summary (m523e <- felm (fail ~ wdidGDPHead_lag + yComEfThis_year + yComEfOther_year + I(wdidGDPHead_lag*yComEfThis_year) + I(wdidGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))
(sum.m523f <- summary (m523f <- felm (fail ~ wdidGDPHead_lag + yComEfThis_year + yComEfOther_year + I(wdidGDPHead_lag*yComEfThis_year) + I(wdidGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))
(sum.m523f2 <- summary (m523f2 <- felm (fail ~ wdidGDPHead_lag + yComEfThis_year + yComEfOther_year + I(wdidGDPHead_lag*yComEfThis_year) + I(wdidGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain[!is.na (wdiMain$oil_gas_valuePOP_2000_lag),])))
(sum.m523g <- summary (m523g <- felm (fail ~ wdidGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(wdidGDPHead_lag*ynoComEfThis_year) + I(wdidGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))
(sum.m523h <- summary (m523h <- felm (fail ~ wdidGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(wdidGDPHead_lag*ynoComEfThis_year) + I(wdidGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))
(sum.m523i <- summary (m523i <- felm (fail ~ wdidGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(wdidGDPHead_lag*yComOnlyLfThis_year) + I(wdidGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(wdidGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))
(sum.m523j <- summary (m523j <- felm (fail ~ wdidGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(wdidGDPHead_lag*yComOnlyLfThis_year) + I(wdidGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(wdidGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, data=wdiMain)))



### (6) Replicating the models reported in Tables A35-A38 and Figures A28-A31: Split samples (6xx models)

## (6.1) 6x1 models: party-based regimes only

# Growth only: 601 models
(sum.m601a <- summary (m601a <- felm (fail ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))
(sum.m601b <- summary (m601b <- felm (fail ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))

# Actual elections: 611 models
(sum.m611a <- summary (m611a <- felm (fail ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))
(sum.m611b <- summary (m611b <- felm (fail ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))
(sum.m611c <- summary (m611c <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))
(sum.m611d <- summary (m611d <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))
(sum.m611e <- summary (m611e <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))
(sum.m611f <- summary (m611f <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))
(sum.m611f2 <- summary (m611f2 <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1 & !is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m611g <- summary (m611g <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))
(sum.m611h <- summary (m611h <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))
(sum.m611i <- summary (m611i <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))
(sum.m611j <- summary (m611j <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))

# Scheduled elections: 621 models
(sum.m621a <- summary (m621a <- felm (fail ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))
(sum.m621b <- summary (m621b <- felm (fail ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))
(sum.m621e <- summary (m621e <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))
(sum.m621f <- summary (m621f <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))
(sum.m621f2 <- summary (m621f2 <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1 & !is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m621g <- summary (m621g <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))
(sum.m621h <- summary (m621h <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))
(sum.m621i <- summary (m621i <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))
(sum.m621j <- summary (m621j <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==1,])))


## (6.2) 6x2 models: regimes that are not party-based only

# Growth only: 602 models
(sum.m602a <- summary (m602a <- felm (fail ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))
(sum.m602b <- summary (m602b <- felm (fail ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))

# Actual elections: 612 models
(sum.m612a <- summary (m612a <- felm (fail ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))
(sum.m612b <- summary (m612b <- felm (fail ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))
(sum.m612c <- summary (m612c <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))
(sum.m612d <- summary (m612d <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))
(sum.m612e <- summary (m612e <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))
(sum.m612f <- summary (m612f <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))
(sum.m612f2 <- summary (m612f2 <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0 & !is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m612g <- summary (m612g <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))
(sum.m612h <- summary (m612h <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))
(sum.m612i <- summary (m612i <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))
(sum.m612j <- summary (m612j <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))

# Scheduled elections: 622 models
(sum.m622a <- summary (m622a <- felm (fail ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))
(sum.m622b <- summary (m622b <- felm (fail ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))
(sum.m622e <- summary (m622e <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))
(sum.m622f <- summary (m622f <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))
(sum.m622f2 <- summary (m622f2 <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0 & !is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m622g <- summary (m622g <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))
(sum.m622h <- summary (m622h <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))
(sum.m622i <- summary (m622i <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))
(sum.m622j <- summary (m622j <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$party2==0,])))


## (6.3) 6x3 models: poor countries only

# Growth only: 603 models
(sum.m603a <- summary (m603a <- felm (fail ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))
(sum.m603b <- summary (m603b <- felm (fail ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))

# Actual elections: 613 models
(sum.m613a <- summary (m613a <- felm (fail ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))
(sum.m613b <- summary (m613b <- felm (fail ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))
(sum.m613c <- summary (m613c <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))
(sum.m613d <- summary (m613d <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))
(sum.m613e <- summary (m613e <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))
(sum.m613f <- summary (m613f <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))
(sum.m613f2 <- summary (m613f2 <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1 & !is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m613g <- summary (m613g <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))
(sum.m613h <- summary (m613h <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))
(sum.m613i <- summary (m613i <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))
(sum.m613j <- summary (m613j <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))

# Scheduled elections: 623 models
(sum.m623a <- summary (m623a <- felm (fail ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))
(sum.m623b <- summary (m623b <- felm (fail ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))
(sum.m623e <- summary (m623e <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))
(sum.m623f <- summary (m623f <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))
(sum.m623f2 <- summary (m623f2 <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1 & !is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m623g <- summary (m623g <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))
(sum.m623h <- summary (m623h <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))
(sum.m623i <- summary (m623i <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))
(sum.m623j <- summary (m623j <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==1,])))


## (6.4) 6x4 models: rich countries only

# Growth only: 604 models
(sum.m604a <- summary (m604a <- felm (fail ~ madddGDPHead_lag + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))
(sum.m604b <- summary (m604b <- felm (fail ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))

# Actual elections: 614 models
(sum.m614a <- summary (m614a <- felm (fail ~ comE + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))
(sum.m614b <- summary (m614b <- felm (fail ~ comE + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))
(sum.m614c <- summary (m614c <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))
(sum.m614d <- summary (m614d <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))
(sum.m614e <- summary (m614e <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))
(sum.m614f <- summary (m614f <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))
(sum.m614f2 <- summary (m614f2 <- felm (fail ~ madddGDPHead_lag + comE + I(madddGDPHead_lag*comE) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comE*ear) + ear + I(comE*ear) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0 & !is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m614g <- summary (m614g <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))
(sum.m614h <- summary (m614h <- felm (fail ~ madddGDPHead_lag + nocomE + I(madddGDPHead_lag*nocomE) + I(madddGDPHead_lag*earNoComp) + I(madddGDPHead_lag*nocomE*earNoComp) + earNoComp + I(nocomE*earNoComp) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))
(sum.m614i <- summary (m614i <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))
(sum.m614j <- summary (m614j <- felm (fail ~ madddGDPHead_lag + comL2 + I(madddGDPHead_lag*comL2) + I(madddGDPHead_lag*ear) + I(madddGDPHead_lag*comL2*ear) + ear + I(comL2*ear) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))

# Scheduled elections: 624 models
(sum.m624a <- summary (m624a <- felm (fail ~ yComEfThis_year + yComEfOther_year + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))
(sum.m624b <- summary (m624b <- felm (fail ~ yComEfThis_year + yComEfOther_year + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))
(sum.m624e <- summary (m624e <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))
(sum.m624f <- summary (m624f <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))
(sum.m624f2 <- summary (m624f2 <- felm (fail ~ madddGDPHead_lag + yComEfThis_year + yComEfOther_year + I(madddGDPHead_lag*yComEfThis_year) + I(madddGDPHead_lag*yComEfOther_year) + log(maddGDPHead_lag) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0 & !is.na (maddMain$oil_gas_valuePOP_2000_lag),])))
(sum.m624g <- summary (m624g <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))
(sum.m624h <- summary (m624h <- felm (fail ~ madddGDPHead_lag + ynoComEfThis_year + ynoComEfOther_year + I(madddGDPHead_lag*ynoComEfThis_year) + I(madddGDPHead_lag*ynoComEfOther_year) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))
(sum.m624i <- summary (m624i <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))
(sum.m624j <- summary (m624j <- felm (fail ~ madddGDPHead_lag + yComOnlyLfThis_year + yComOnlyLfOther_year + I(madddGDPHead_lag*yComOnlyLfThis_year) + I(madddGDPHead_lag*yComOnlyLfOther_year) + yComOnlyLfThis_year_both + I(madddGDPHead_lag*yComOnlyLfThis_year_both) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + poly (duration, 3) | idRegime + year.f | 0 | idRegime, maddMain[maddMain$poor50==0,])))



### (7) Replicating the models reported in Table A18: Electoral manipulation (7xx models)

## (7.1) 7x1 models: harassment of the opposition (NELDA)

# Growth only: 701 models
(sum.m701a <- summary (m701a <- glm (nHarassment ~ madddGDPHead_lag, family=binomial (link="probit"), data=maddMain[maddMain$comE==1,])))
vcov.m701a <- cluster.vcov (m701a, cluster = ~ idRegime)
(coef.m701a <- coeftest (m701a, vcov.m701a))
(sum.m701b <- summary (m701b <- glm (nHarassment ~ madddGDPHead_lag + log(maddGDPHead_lag) + propDemo + party2 + military2 + personal2 + coldWar + region, family=binomial (link="probit"), data=maddMain[maddMain$comE==1,])))
vcov.m701b <- cluster.vcov (m701b, cluster = ~ idRegime)
(coef.m701b <- coeftest (m701b, vcov.m701b))
(sum.m701c <- summary (m701c <- glm (nHarassment ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + coldWar + region, family=binomial (link="probit"), data=maddMain[maddMain$comE==1,])))
vcov.m701c <- cluster.vcov (m701c, cluster = ~ idRegime)
(coef.m701c <- coeftest (m701c, vcov.m701c))
(sum.m701d <- summary (m701d <- felm (nHarassment ~ madddGDPHead_lag | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m701e <- summary (m701e <- felm (nHarassment ~ madddGDPHead_lag + log(maddGDPHead_lag) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m701f <- summary (m701f <- felm (nHarassment ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))

# Breakdown only: 711 models
(sum.m711a <- summary (m711a <- glm (nHarassment ~ fail, family=binomial (link="probit"), data=maddMain[maddMain$comE==1,])))
vcov.m711a <- cluster.vcov (m711a, cluster = ~ idRegime)
(coef.m711a <- coeftest (m711a, vcov.m711a))
(sum.m711b <- summary (m711b <- glm (nHarassment ~ fail + log(maddGDPHead_lag) + propDemo + party2 + military2 + personal2 + coldWar + region, family=binomial (link="probit"), data=maddMain[maddMain$comE==1,])))
vcov.m711b <- cluster.vcov (m711b, cluster = ~ idRegime)
(coef.m711b <- coeftest (m711b, vcov.m711b))
(sum.m711c <- summary (m711c <- glm (nHarassment ~ fail + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + coldWar + region, family=binomial (link="probit"), data=maddMain[maddMain$comE==1,])))
vcov.m711c <- cluster.vcov (m711c, cluster = ~ idRegime)
(coef.m711c <- coeftest (m711c, vcov.m711c))
(sum.m711d <- summary (m711d <- felm (nHarassment ~ fail | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m711e <- summary (m711e <- felm (nHarassment ~ fail + log(maddGDPHead_lag) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m711f <- summary (m711f <- felm (nHarassment ~ fail + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))

# Interaction between the two: 721 models
(sum.m721a <- summary (m721a <- glm (nHarassment ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail), family=binomial (link="probit"), data=maddMain[maddMain$comE==1,])))
vcov.m721a <- cluster.vcov (m721a, cluster = ~ idRegime)
(coef.m721a <- coeftest (m721a, vcov.m721a))
(sum.m721b <- summary (m721b <- glm (nHarassment ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) + log(maddGDPHead_lag) + propDemo + party2 + military2 + personal2 + coldWar + region, family=binomial (link="probit"), data=maddMain[maddMain$comE==1,])))
vcov.m721b <- cluster.vcov (m721b, cluster = ~ idRegime)
(coef.m721b <- coeftest (m721b, vcov.m721b))
(sum.m721c <- summary (m721c <- glm (nHarassment ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + coldWar + region, family=binomial (link="probit"), data=maddMain[maddMain$comE==1,])))
vcov.m721c <- cluster.vcov (m721c, cluster = ~ idRegime)
(coef.m721c <- coeftest (m721c, vcov.m721c))
(sum.m721d <- summary (m721d <- felm (nHarassment ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m721e <- summary (m721e <- felm (nHarassment ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) + log(maddGDPHead_lag) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m721f <- summary (m721f <- felm (nHarassment ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))



## (7.2) 7x2 models: elections free and fair (V-Dem)

# Growth only: 702 models
(sum.m702a <- summary (m702a <- felm (v2elfrfair ~ madddGDPHead_lag | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m702b <- summary (m702b <- felm (v2elfrfair ~ madddGDPHead_lag + log(maddGDPHead_lag) + propDemo + party2 + military2 + personal2 + coldWar + region | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m702c <- summary (m702c <- felm (v2elfrfair ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + coldWar + region | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m702d <- summary (m702d <- felm (v2elfrfair ~ madddGDPHead_lag | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m702e <- summary (m702e <- felm (v2elfrfair ~ madddGDPHead_lag + log(maddGDPHead_lag) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m702f <- summary (m702f <- felm (v2elfrfair ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))

# Breakdown only: 712 models
(sum.m712a <- summary (m712a <- felm (v2elfrfair ~ fail | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m712b <- summary (m712b <- felm (v2elfrfair ~ fail + log(maddGDPHead_lag) + propDemo + party2 + military2 + personal2 + coldWar + region | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m712c <- summary (m712c <- felm (v2elfrfair ~ fail + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + coldWar + region | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m712d <- summary (m712d <- felm (v2elfrfair ~ fail | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m712e <- summary (m712e <- felm (v2elfrfair ~ fail + log(maddGDPHead_lag) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m712f <- summary (m712f <- felm (v2elfrfair ~ fail + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))

# Interaction between the two: 722 models
(sum.m722a <- summary (m722a <- felm (v2elfrfair ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m722b <- summary (m722b <- felm (v2elfrfair ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) + log(maddGDPHead_lag) + propDemo + party2 + military2 + personal2 + coldWar + region | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m722c <- summary (m722c <- felm (v2elfrfair ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + coldWar + region | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m722d <- summary (m722d <- felm (v2elfrfair ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m722e <- summary (m722e <- felm (v2elfrfair ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) + log(maddGDPHead_lag) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m722f <- summary (m722f <- felm (v2elfrfair ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))


## (7.3) 7x3 models: electoral irregularities (V-Dem)

# Growth only: 703 models
(sum.m703a <- summary (m703a <- felm (v2elirreg ~ madddGDPHead_lag | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m703b <- summary (m703b <- felm (v2elirreg ~ madddGDPHead_lag + log(maddGDPHead_lag) + propDemo + party2 + military2 + personal2 + coldWar + region | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m703c <- summary (m703c <- felm (v2elirreg ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + coldWar + region | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m703d <- summary (m703d <- felm (v2elirreg ~ madddGDPHead_lag | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m703e <- summary (m703e <- felm (v2elirreg ~ madddGDPHead_lag + log(maddGDPHead_lag) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m703f <- summary (m703f <- felm (v2elirreg ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))

# Breakdown only: 713 models
(sum.m713a <- summary (m713a <- felm (v2elirreg ~ fail | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m713b <- summary (m713b <- felm (v2elirreg ~ fail + log(maddGDPHead_lag) + propDemo + party2 + military2 + personal2 + coldWar + region | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m713c <- summary (m713c <- felm (v2elirreg ~ fail + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + coldWar + region | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m713d <- summary (m713d <- felm (v2elirreg ~ fail | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m713e <- summary (m713e <- felm (v2elirreg ~ fail + log(maddGDPHead_lag) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m713f <- summary (m713f <- felm (v2elirreg ~ fail + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))

# Interaction between the two: 723 models
(sum.m723a <- summary (m723a <- felm (v2elirreg ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m723b <- summary (m723b <- felm (v2elirreg ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) + log(maddGDPHead_lag) + propDemo + party2 + military2 + personal2 + coldWar + region | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m723c <- summary (m723c <- felm (v2elirreg ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + coldWar + region | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m723d <- summary (m723d <- felm (v2elirreg ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m723e <- summary (m723e <- felm (v2elirreg ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) + log(maddGDPHead_lag) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m723f <- summary (m723f <- felm (v2elirreg ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))


## (7.4) 7x4 models: election intimidation (V-Dem)

# Growth only: 704 models
(sum.m704a <- summary (m704a <- felm (v2elintim ~ madddGDPHead_lag | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m704b <- summary (m704b <- felm (v2elintim ~ madddGDPHead_lag + log(maddGDPHead_lag) + propDemo + party2 + military2 + personal2 + coldWar + region | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m704c <- summary (m704c <- felm (v2elintim ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + coldWar + region | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m704d <- summary (m704d <- felm (v2elintim ~ madddGDPHead_lag | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m704e <- summary (m704e <- felm (v2elintim ~ madddGDPHead_lag + log(maddGDPHead_lag) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m704f <- summary (m704f <- felm (v2elintim ~ madddGDPHead_lag + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))

# Breakdown only: 714 models
(sum.m714a <- summary (m714a <- felm (v2elintim ~ fail | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m714b <- summary (m714b <- felm (v2elintim ~ fail + log(maddGDPHead_lag) + propDemo + party2 + military2 + personal2 + coldWar + region | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m714c <- summary (m714c <- felm (v2elintim ~ fail + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + coldWar + region | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m714d <- summary (m714d <- felm (v2elintim ~ fail | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m714e <- summary (m714e <- felm (v2elintim ~ fail + log(maddGDPHead_lag) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m714f <- summary (m714f <- felm (v2elintim ~ fail + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))

# Interaction between the two: 724 models
(sum.m724a <- summary (m724a <- felm (v2elintim ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m724b <- summary (m724b <- felm (v2elintim ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) + log(maddGDPHead_lag) + propDemo + party2 + military2 + personal2 + coldWar + region | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m724c <- summary (m724c <- felm (v2elintim ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + party2 + military2 + personal2 + coldWar + region | 0 | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m724d <- summary (m724d <- felm (v2elintim ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m724e <- summary (m724e <- felm (v2elintim ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) + log(maddGDPHead_lag) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))
(sum.m724f <- summary (m724f <- felm (v2elintim ~ madddGDPHead_lag + fail + I(madddGDPHead_lag*fail) + log(maddGDPHead_lag) + log (oil_gas_valuePOP_2000_lag+1) + propDemo + coldWar | idRegime | 0 | idRegime, maddMain[maddMain$comE==1,])))







########## BUILDING THE TABLES

## function for adding parentheses automatically:
parSE <- function (x, n.digits){
  txt <- paste ("%.", n.digits, "f", sep="")
  x.tmp <- matrix (as.character (sprintf (as.character (txt), as.matrix (round (x, n.digits)))), ncol=ncol (x), byrow=F)
  #x.tmp <- matrix (as.character (sprintf (as.character (txt), as.character (round (x, n.digits)))), ncol=ncol (x), byrow=F)
  x.tmp[seq (2, nrow (x.tmp), by=2),] <- paste ("(", x.tmp[seq (2, nrow (x.tmp), by=2),], ")", sep="")
  x.tmp <- sub ("\\(NA\\)", x.tmp, replacement="")
  x.tmp <- sub ("NA", x.tmp, replacement="")
  return (x.tmp)
}
n.digit <- 2


## setting the graphical parameters
col.fill <- "coral"
col.estim <- "darkcyan"
col.line <- "gray50"
col.hist <- "gray75"
col.scale <- "PuBu"
col.label <- "black"
m <- 500 # number of points for drawing the lines for the marginal effect(s) of elections on breakdown
h.lim <- 0.25  ## to plot the effect of elections|growth for values of growth between -0.3 y 0.3
b <- 100  ## histogram bins
cex.line <- 0.3
cex.out <- 0.3
cex.bars <- 0.15
cex.text <- 18
dodge <- position_dodge (width=0.9)
(aspect.ratio <- 2.25/1)
plotWidth <- 840


### (1) Replicating Figure 1

# quantiles for growth rates
(mainQuant4 <- with (maddMain, quantile (madddGDPHead_lag, probs=c (0.25, 0.50, 0.75))))
maddMain$gQt41 <- with (maddMain, ifelse (round (madddGDPHead_lag, 5) <= mainQuant4[1], 1, 0))
maddMain$gQt42 <- with (maddMain, ifelse (round (madddGDPHead_lag, 5) > mainQuant4[1] & madddGDPHead_lag <= mainQuant4[2], 1, 0))
maddMain$gQt43 <- with (maddMain, ifelse (round (madddGDPHead_lag, 5) > mainQuant4[2] & madddGDPHead_lag <= mainQuant4[3], 1, 0))
maddMain$gQt44 <- with (maddMain, ifelse (round (madddGDPHead_lag, 5) > mainQuant4[3], 1, 0))

# sample sizes
(nobsMain.qt4 <- cbind (
  
  # (a) full sample
  c (nrow (maddMain), with (maddMain, c (sum (gQt41), sum (gQt42), sum (gQt43), sum (gQt44))))
  
  # (b) closed vs. EARs
  , c (nrow (maddMain[maddMain$closed==1,]), with (maddMain[maddMain$closed==1,], c (sum (gQt41), sum (gQt42), sum (gQt43), sum (gQt44))))
  , c (nrow (maddMain[maddMain$ear==1,]), with (maddMain[maddMain$ear==1,], c (sum (gQt41), sum (gQt42), sum (gQt43), sum (gQt44))))
  
  # (c) separating election and non-election years in EARs
  , c (nrow (maddMain[maddMain$closed==1,]), with (maddMain[maddMain$closed==1,], c (sum (gQt41), sum (gQt42), sum (gQt43), sum (gQt44))))
  , c (nrow (maddMain[maddMain$ear==1 & maddMain$comE==0,]), with (maddMain[maddMain$ear==1 & maddMain$comE==0,], c (sum (gQt41), sum (gQt42), sum (gQt43), sum (gQt44))))
  , c (nrow (maddMain[maddMain$ear==1 & maddMain$comE==1,]), with (maddMain[maddMain$ear==1 & maddMain$comE==1,], c (sum (gQt41), sum (gQt42), sum (gQt43), sum (gQt44))))
))

# sample breakdowns
(nfailMain.qt4 <- cbind (
  
  # (a) full sample
  c (nrow (maddMain[maddMain$fail==1,]), with (maddMain[maddMain$fail==1,], c (sum (gQt41), sum (gQt42), sum (gQt43), sum (gQt44))))
  
  # (b) closed vs. EARs
  , c (nrow (maddMain[maddMain$closed==1 & maddMain$fail==1,]), with (maddMain[maddMain$closed==1 & maddMain$fail==1,], c (sum (gQt41), sum (gQt42), sum (gQt43), sum (gQt44))))
  , c (nrow (maddMain[maddMain$ear==1 & maddMain$fail==1,]), with (maddMain[maddMain$ear==1 & maddMain$fail==1,], c (sum (gQt41), sum (gQt42), sum (gQt43), sum (gQt44))))
  
  # (c) separating election and non-election years in EARs
  , c (nrow (maddMain[maddMain$closed==1 & maddMain$fail==1,]), with (maddMain[maddMain$closed==1 & maddMain$fail==1,], c (sum (gQt41), sum (gQt42), sum (gQt43), sum (gQt44))))
  , c (nrow (maddMain[maddMain$ear==1 & maddMain$comE==0 & maddMain$fail==1,]), with (maddMain[maddMain$ear==1 & maddMain$comE==0 & maddMain$fail==1,], c (sum (gQt41), sum (gQt42), sum (gQt43), sum (gQt44))))
  , c (nrow (maddMain[maddMain$ear==1 & maddMain$comE==1 & maddMain$fail==1,]), with (maddMain[maddMain$ear==1 & maddMain$comE==1 & maddMain$fail==1,], c (sum (gQt41), sum (gQt42), sum (gQt43), sum (gQt44))))
))

(pfailMain.qt4 <- round ((nfailMain.qt4 / nobsMain.qt4)*100, 1))  ## this is what we expected. Good


## Drawing the plot

# dataset for ggplot2
round (mainQuant4*100, 1)  ## to get the cutoffs of interest
(freqsMain.qt4 <- as.data.frame (cbind (
  c (rep ("(a) Full\nsample", 4), rep ("(b) Disaggregating by\nregime type", 8), rep ("(c) Distinguishing between election and\nnon-elections years in EARs", 12))
  , rep (c ("growth\n1st quartile\n(< -0.8%]", "growth\n2nd quartile\n(-0.8%:2.1%]", "growth\n3rd quartile\n(2.1%:4.8%]", "growth\n4th quartile\n(> 4.8%)"), 6)
  , c (rep ("all\nobservations", 4), rep ("closed", 4), rep ("EAR", 4), rep ("closed", 4), rep ("EAR\n(no election)", 4), rep ("EAR\n(election)", 4))
  , paste (sprintf ("%.1f", pfailMain.qt4[2:5,]), "%\n[", sprintf ("%.0f", nobsMain.qt4[2:5,]), "]", sep="")
  , c (pfailMain.qt4[2:5,])  
)))
colnames (freqsMain.qt4) <- c ("panel", "growth", "sample", "txt", "fail")
freqsMain.qt4$growth <- factor (freqsMain.qt4$growth, levels=levels (freqsMain.qt4$growth)[1:4])
freqsMain.qt4$sample <- factor (freqsMain.qt4$sample, levels=levels (freqsMain.qt4$sample)[c (5, 1, 2, 4, 3)])
freqsMain.qt4$txt <- as.character (freqsMain.qt4$txt)
freqsMain.qt4$fail <- as.numeric (as.character (freqsMain.qt4$fail))
freqsMain.qt4$sample <- factor (freqsMain.qt4$sample, levels=c ("all\nobservations", "closed", "EAR", "EAR\n(no election)", "EAR\n(election)"))

# plot
(pFreqsMain.qt4 <- ggplot (freqsMain.qt4, aes (x=sample, y=growth, fill=fail))
  + geom_tile ()
  + geom_text (aes (label=txt), colour=col.label, size=cex.text/2.5)
  + scale_fill_distiller (palette = col.scale, direction=1)
  + guides (fill=FALSE)
  + theme_bw (base_size=cex.text)
  + ylab ("")
  + xlab ("") 
  + facet_grid (. ~ panel, scales="free", space="free")
  + theme (strip.text.x = element_text (size = cex.text)))

# exporting the plot
png ("Figures/fig_failPuBuMain.png", w=plotWidth*1.2, h=plotWidth/1.5)
pFreqsMain.qt4
dev.off ()


### (2) Main results: Table 1 and A6-A7 and Figures 2 and A1

# (2.1) Tables 1 and A6 (they are identical, only difference is what is reported)
(coefMain01a <- cbind (
  c (sum.m100a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m101a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m102a$coef[1:3,1], rep (NA, 6+5), sum.m102a$coef[1,1], sum.m102a$coef[1,1], sum.m102a$coef[1,1]+sum.m102a$coef[3,1], sum.m102a$coef[1,1]+sum.m102a$coef[3,1])
  , c (sum.m103a$coef[1:7,1], rep (NA, 2+5), sum.m103a$coef[1,1], sum.m103a$coef[1,1]+sum.m103a$coef[4,1], sum.m103a$coef[1,1]+sum.m103a$coef[3,1], sum.m103a$coef[1,1]+sum.m103a$coef[3,1]+sum.m103a$coef[4,1]+sum.m103a$coef[5,1])
  , c (sum.m103f$coef[1:7,1], rep (NA, 2+2), sum.m103f$coef[8:10,1], sum.m103f$coef[1,1], sum.m103f$coef[1,1]+sum.m103f$coef[4,1], sum.m103f$coef[1,1]+sum.m103f$coef[3,1], sum.m103f$coef[1,1]+sum.m103f$coef[3,1]+sum.m103f$coef[4,1]+sum.m103f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m110a$coef[1,1], rep (NA, 5), sum.m110a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m111a$coef[c (1:2,4),1], rep (NA, 4), sum.m111a$coef[c (3,5),1], rep (NA, 5), sum.m111a$coef[1,1], sum.m111a$coef[1,1]+sum.m111a$coef[5,1], NA, sum.m111a$coef[1,1]+sum.m111a$coef[4,1])
  , c (sum.m111f$coef[c (1:2,4),1], rep (NA, 4), sum.m111f$coef[c (3,5),1], rep (NA, 2), sum.m111f$coef[6:8,1], sum.m111f$coef[1,1], sum.m111f$coef[1,1]+sum.m111f$coef[5,1], NA, sum.m111f$coef[1,1]+sum.m111f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m105a$coef[1:7,1], rep (NA, 2+5), sum.m105a$coef[1,1], sum.m105a$coef[1,1]+sum.m105a$coef[4,1], sum.m105a$coef[1,1]+sum.m105a$coef[3,1], sum.m105a$coef[1,1]+sum.m105a$coef[3,1]+sum.m105a$coef[4,1]+sum.m105a$coef[5,1])
  , c (sum.m113a$coef[c (1:2,4),1], rep (NA, 4), sum.m113a$coef[c (3,5),1], rep (NA, 5), sum.m113a$coef[1,1], sum.m113a$coef[1,1]+sum.m113a$coef[5,1], NA, sum.m113a$coef[1,1]+sum.m113a$coef[4,1])
  , rep (NA, 18)
  , c (sum.m109a$coef[1:7,1], rep (NA, 2+5), sum.m109a$coef[1,1], sum.m109a$coef[1,1]+sum.m109a$coef[4,1], sum.m109a$coef[1,1]+sum.m109a$coef[3,1], sum.m109a$coef[1,1]+sum.m109a$coef[3,1]+sum.m109a$coef[4,1]+sum.m109a$coef[5,1])
  , c (sum.m117a$coef[c (1:2,4),1], rep (NA, 4), sum.m117a$coef[c (3,5:7),1], rep (NA, 3), sum.m117a$coef[1,1], sum.m117a$coef[1,1]+sum.m117a$coef[5,1], NA, sum.m117a$coef[1,1]+sum.m117a$coef[4,1])))
(seMain01a <- cbind (
  c (sum.m100a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m101a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m102a$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m102a)[1,1])
       , sqrt (vcov (m102a)[1,1])
       , sqrt (vcov (m102a)[1,1]+1^2*vcov (m102a)[3,3]+2*1*vcov (m102a)[1,3])
       , sqrt (vcov (m102a)[1,1]+1^2*vcov (m102a)[3,3]+2*1*vcov (m102a)[1,3]))
  , c (sum.m103a$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m103a)[1,1])
       , sqrt (vcov (m103a)[1,1]+1^2*vcov (m103a)[4,4]+2*1*vcov (m103a)[1,4])
       , sqrt (vcov (m103a)[1,1]+1^2*vcov (m103a)[3,3]+2*1*vcov (m103a)[1,3])
       , sqrt (vcov (m103a)[1,1]+1^2*vcov (m103a)[3,3]+1^2*vcov (m103a)[4,4]+1^2*1^2*vcov (m103a)[5,5]+2*1*vcov (m103a)[1,3]+2*1*vcov (m103a)[1,4]+2*1*1*vcov (m103a)[1,5]+2*1*1*vcov (m103a)[3,4]+2*1*1^2*vcov (m103a)[3,5]+2*1*1^2*vcov (m103a)[4,5]))
  , c (sum.m103f$coef[1:7,2], rep (NA, 2+2), sum.m103f$coef[8:10,2]
       , sqrt (vcov (m103f)[1,1])
       , sqrt (vcov (m103f)[1,1]+1^2*vcov (m103f)[4,4]+2*1*vcov (m103f)[1,4])
       , sqrt (vcov (m103f)[1,1]+1^2*vcov (m103f)[3,3]+2*1*vcov (m103f)[1,3])
       , sqrt (vcov (m103f)[1,1]+1^2*vcov (m103f)[3,3]+1^2*vcov (m103f)[4,4]+1^2*1^2*vcov (m103f)[5,5]+2*1*vcov (m103f)[1,3]+2*1*vcov (m103f)[1,4]+2*1*1*vcov (m103f)[1,5]+2*1*1*vcov (m103f)[3,4]+2*1*1^2*vcov (m103f)[3,5]+2*1*1^2*vcov (m103f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m110a$coef[1,2], rep (NA, 5), sum.m110a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m111a$coef[c (1:2,4),2], rep (NA, 4), sum.m111a$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m111a)[1,1])
       , sqrt (vcov (m111a)[1,1]+1^2*vcov (m111a)[5,5]+2*1*vcov (m111a)[1,5])
       , NA
       , sqrt (vcov (m111a)[1,1]+1^2*vcov (m111a)[4,4]+2*1*vcov (m111a)[1,4]))
  , c (sum.m111f$coef[c (1:2,4),2], rep (NA, 4), sum.m111f$coef[c (3,5),2], rep (NA, 2), sum.m111f$coef[6:8,2]
       , sqrt (vcov (m111f)[1,1])
       , sqrt (vcov (m111f)[1,1]+1^2*vcov (m111f)[5,5]+2*1*vcov (m111f)[1,5])
       , NA
       , sqrt (vcov (m111f)[1,1]+1^2*vcov (m111f)[4,4]+2*1*vcov (m111f)[1,4]))
  , rep (NA, 18)
  , c (sum.m105a$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m105a)[1,1])
       , sqrt (vcov (m105a)[1,1]+1^2*vcov (m105a)[4,4]+2*1*vcov (m105a)[1,4])
       , sqrt (vcov (m105a)[1,1]+1^2*vcov (m105a)[3,3]+2*1*vcov (m105a)[1,3])
       , sqrt (vcov (m105a)[1,1]+1^2*vcov (m105a)[3,3]+1^2*vcov (m105a)[4,4]+1^2*1^2*vcov (m105a)[5,5]+2*1*vcov (m105a)[1,3]+2*1*vcov (m105a)[1,4]+2*1*1*vcov (m105a)[1,5]+2*1*1*vcov (m105a)[3,4]+2*1*1^2*vcov (m105a)[3,5]+2*1*1^2*vcov (m105a)[4,5]))
  , c (sum.m113a$coef[c (1:2,4),2], rep (NA, 4), sum.m113a$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m113a)[1,1])
       , sqrt (vcov (m113a)[1,1]+1^2*vcov (m113a)[5,5]+2*1*vcov (m113a)[1,5])
       , NA
       , sqrt (vcov (m113a)[1,1]+1^2*vcov (m113a)[4,4]+2*1*vcov (m113a)[1,4]))
  , rep (NA, 18)
  , c (sum.m109a$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m109a)[1,1])
       , sqrt (vcov (m109a)[1,1]+1^2*vcov (m109a)[4,4]+2*1*vcov (m109a)[1,4])
       , sqrt (vcov (m109a)[1,1]+1^2*vcov (m109a)[3,3]+2*1*vcov (m109a)[1,3])
       , sqrt (vcov (m109a)[1,1]+1^2*vcov (m109a)[3,3]+1^2*vcov (m109a)[4,4]+1^2*1^2*vcov (m109a)[5,5]+2*1*vcov (m109a)[1,3]+2*1*vcov (m109a)[1,4]+2*1*1*vcov (m109a)[1,5]+2*1*1*vcov (m109a)[3,4]+2*1*1^2*vcov (m109a)[3,5]+2*1*1^2*vcov (m109a)[4,5]))
  , c (sum.m117a$coef[c (1:2,4),2], rep (NA, 4), sum.m117a$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m117a)[1,1])
       , sqrt (vcov (m117a)[1,1]+1^2*vcov (m117a)[5,5]+2*1*vcov (m117a)[1,5])
       , NA
       , sqrt (vcov (m117a)[1,1]+1^2*vcov (m117a)[4,4]+2*1*vcov (m117a)[1,4]))))

odd <- seq (1, nrow (coefMain01a)*2, by=2); even <- seq (2, nrow (coefMain01a)*2, by=2)
(coefMain01tab <- data.frame (rbind (coefMain01a, seMain01a))) ## warnings reported. Don't worry
rownames (coefMain01tab) <- c (odd, even)
coefMain01tab <- coefMain01tab[order (as.numeric (rownames (coefMain01tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m100a$N, length (unique (sum.m100a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m100a$fe$year.f)))
  , c (sum.m101a$N, length (unique (sum.m101a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m101a$fe$year.f)))
  , c (sum.m102a$N, length (unique (sum.m102a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m102a$fe$year.f)))
  , c (sum.m103a$N, length (unique (sum.m103a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m103a$fe$year.f)))
  , c (sum.m103f$N, length (unique (sum.m103f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m103f$fe$year.f)))
  , c (sum.m110a$N, length (unique (sum.m110a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m110a$fe$year.f)))
  , c (sum.m111a$N, length (unique (sum.m111a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m111a$fe$year.f)))
  , c (sum.m111f$N, length (unique (sum.m111f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m111f$fe$year.f)))
  , c (sum.m105a$N, length (unique (sum.m105a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m105a$fe$year.f)))
  , c (sum.m113a$N, length (unique (sum.m113a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m113a$fe$year.f)))
  , c (sum.m109a$N, length (unique (sum.m109a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m109a$fe$year.f)))
  , c (sum.m117a$N, length (unique (sum.m117a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m117a$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefMain01tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Elections, economic performance and authoritarian breakdown, 1948-2011"
               , label="T:main")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

# (2.2) Table A7
(coefMain02a <- cbind (
  c (sum.m100a$coef[1,1], rep (NA, 8+8+3+6))
  , rep (NA, 26)
  , c (NA, sum.m106a$coef[1,1], rep (NA, 7), sum.m106a$coef[2,1], rep (NA, 7+3+6))
  , c (sum.m106b$coef[1:3,1], rep (NA, 6), sum.m106b$coef[4:5,1], rep (NA, 6+3), sum.m106b$coef[1,1], sum.m106b$coef[1,1], sum.m106b$coef[1,1], NA, sum.m106b$coef[1,1]+sum.m106b$coef[5,1], sum.m106b$coef[1,1]+sum.m106b$coef[3,1])
  , c (sum.m107a$coef[1:7,1], rep (NA, 2), sum.m107a$coef[8:13,1], rep (NA, 2+3), sum.m107a$coef[1,1], sum.m107a$coef[1,1]+sum.m107a$coef[10,1], sum.m107a$coef[1,1]+sum.m107a$coef[4,1], sum.m107a$coef[1,1]+sum.m107a$coef[3,1], sum.m107a$coef[1,1]+sum.m107a$coef[9,1]+sum.m107a$coef[10,1]+sum.m107a$coef[11,1],sum.m107a$coef[1,1]+sum.m107a$coef[3,1]+sum.m107a$coef[4,1]+sum.m107a$coef[5,1])
  , c (sum.m107f$coef[1:7,1], rep (NA, 2), sum.m107f$coef[8:13,1], rep (NA, 2), sum.m107f$coef[14:16,1], sum.m107f$coef[1,1], sum.m107f$coef[1,1]+sum.m107f$coef[10,1], sum.m107f$coef[1,1]+sum.m107f$coef[4,1], sum.m107f$coef[1,1]+sum.m107f$coef[3,1], sum.m107f$coef[1,1]+sum.m107f$coef[9,1]+sum.m107f$coef[10,1]+sum.m107f$coef[11,1],sum.m107f$coef[1,1]+sum.m107f$coef[3,1]+sum.m107f$coef[4,1]+sum.m107f$coef[5,1])
  , rep (NA, 26)
  , c (NA, sum.m114a$coef[1,1], rep (NA, 5), sum.m114a$coef[3,1], NA, sum.m114a$coef[2,1], rep (NA, 5), sum.m114a$coef[4,1], rep (NA, 1+3+6))
  , c (sum.m115a$coef[c (1:2,9),1], rep (NA, 4), sum.m115a$coef[c (4,11,3,10),1], rep (NA, 4), sum.m115a$coef[c (5,12),1], rep (NA, 3), sum.m115a$coef[1,1], sum.m115a$coef[1,1]+sum.m115a$coef[12,1], sum.m115a$coef[1,1]+sum.m115a$coef[11,1], NA, sum.m115a$coef[1,1]+sum.m115a$coef[10,1], sum.m115a$coef[1,1]+sum.m115a$coef[9,1])
  , c (sum.m115f$coef[c (1:2,12),1], rep (NA, 4), sum.m115f$coef[c (4,14,3,13),1], rep (NA, 4), sum.m115f$coef[c (5,15,6:8),1], sum.m115f$coef[1,1], sum.m115f$coef[1,1]+sum.m115f$coef[15,1], sum.m115f$coef[1,1]+sum.m115f$coef[14,1], NA, sum.m115f$coef[1,1]+sum.m115f$coef[13,1], sum.m115f$coef[1,1]+sum.m115f$coef[12,1])))
(seMain02a <- cbind (
  c (sum.m100a$coef[1,2], rep (NA, 8+8+3+6))
  , rep (NA, 26)
  , c (NA, sum.m106a$coef[1,2], rep (NA, 7), sum.m106a$coef[2,2], rep (NA, 7+3+6))
  , c (sum.m106b$coef[1:3,2], rep (NA, 6), sum.m106b$coef[4:5,2], rep (NA, 6+3)
       , sqrt (vcov (m106b)[1,1])
       , sqrt (vcov (m106b)[1,1])
       , sqrt (vcov (m106b)[1,1])
       , NA
       , sqrt (vcov (m106b)[1,1]+1^2*vcov (m106b)[5,5]+2*1*vcov (m106b)[1,5])
       , sqrt (vcov (m106b)[1,1]+1^2*vcov (m106b)[3,3]+2*1*vcov (m106b)[1,3]))
  , c (sum.m107a$coef[1:7,2], rep (NA, 2), sum.m107a$coef[8:13,2], rep (NA, 2+3)
       , sqrt (vcov (m107a)[1,1])
       , sqrt (vcov (m107a)[1,1]+1^2*vcov (m107a)[10,10]+2*1*vcov (m107a)[1,10])
       , sqrt (vcov (m107a)[1,1]+1^2*vcov (m107a)[4,4]+2*1*vcov (m107a)[1,4])
       , sqrt (vcov (m107a)[1,1]+1^2*vcov (m107a)[3,3]+2*1*vcov (m107a)[1,3])
       , sqrt (vcov (m107a)[1,1]+1^2*vcov (m107a)[9,9]+1^2*vcov (m107a)[10,10]+1^2*1^2*vcov (m107a)[11,11]+2*1*vcov (m107a)[1,9]+2*1*vcov (m107a)[1,10]+2*1*1*vcov (m107a)[1,11]+2*1*1*vcov (m107a)[9,10]+2*1*1^2*vcov (m107a)[9,11]+2*1*1^2*vcov (m107a)[10,11])
       , sqrt (vcov (m107a)[1,1]+1^2*vcov (m107a)[3,3]+1^2*vcov (m107a)[4,4]+1^2*1^2*vcov (m107a)[5,5]+2*1*vcov (m107a)[1,3]+2*1*vcov (m107a)[1,4]+2*1*1*vcov (m107a)[1,5]+2*1*1*vcov (m107a)[3,4]+2*1*1^2*vcov (m107a)[3,5]+2*1*1^2*vcov (m107a)[4,5]))
  , c (sum.m107f$coef[1:7,2], rep (NA, 2), sum.m107f$coef[8:13,2], rep (NA, 2), sum.m107f$coef[14:16,2]
       , sqrt (vcov (m107f)[1,1])
       , sqrt (vcov (m107f)[1,1]+1^2*vcov (m107f)[10,10]+2*1*vcov (m107f)[1,10])
       , sqrt (vcov (m107f)[1,1]+1^2*vcov (m107f)[4,4]+2*1*vcov (m107f)[1,4])
       , sqrt (vcov (m107f)[1,1]+1^2*vcov (m107f)[3,3]+2*1*vcov (m107f)[1,3])
       , sqrt (vcov (m107f)[1,1]+1^2*vcov (m107f)[9,9]+1^2*vcov (m107f)[10,10]+1^2*1^2*vcov (m107f)[11,11]+2*1*vcov (m107f)[1,9]+2*1*vcov (m107f)[1,10]+2*1*1*vcov (m107f)[1,11]+2*1*1*vcov (m107f)[9,10]+2*1*1^2*vcov (m107f)[9,11]+2*1*1^2*vcov (m107f)[10,11])
       , sqrt (vcov (m107f)[1,1]+1^2*vcov (m107f)[3,3]+1^2*vcov (m107f)[4,4]+1^2*1^2*vcov (m107f)[5,5]+2*1*vcov (m107f)[1,3]+2*1*vcov (m107f)[1,4]+2*1*1*vcov (m107f)[1,5]+2*1*1*vcov (m107f)[3,4]+2*1*1^2*vcov (m107f)[3,5]+2*1*1^2*vcov (m107f)[4,5]))
  , rep (NA, 26)
  , c (NA, sum.m114a$coef[1,2], rep (NA, 5), sum.m114a$coef[3,2], NA, sum.m114a$coef[2,2], rep (NA, 5), sum.m114a$coef[4,2], rep (NA, 1+3+6))
  , c (sum.m115a$coef[c (1:2,9),2], rep (NA, 4), sum.m115a$coef[c (4,11,3,10),2], rep (NA, 4), sum.m115a$coef[c (5,12),2], rep (NA, 3)
       , sqrt (vcov (m115a)[1,1])
       , sqrt (vcov (m115a)[1,1]+1^2*vcov (m115a)[12,12]+2*1*vcov (m115a)[1,12])
       , sqrt (vcov (m115a)[1,1]+1^2*vcov (m115a)[11,11]+2*1*vcov (m115a)[1,11])
       , NA
       , sqrt (vcov (m115a)[1,1]+1^2*vcov (m115a)[10,10]+2*1*vcov (m115a)[1,10])
       , sqrt (vcov (m115a)[1,1]+1^2*vcov (m115a)[9,9]+2*1*vcov (m115a)[1,9]))
  , c (sum.m115f$coef[c (1:2,12),2], rep (NA, 4), sum.m115f$coef[c (4,14,3,13),2], rep (NA, 4), sum.m115f$coef[c (5,15,6:8),2]
       , sqrt (vcov (m115f)[1,1])
       , sqrt (vcov (m115f)[1,1]+1^2*vcov (m115f)[15,15]+2*1*vcov (m115f)[1,15])
       , sqrt (vcov (m115f)[1,1]+1^2*vcov (m115f)[14,14]+2*1*vcov (m115f)[1,14])
       , NA
       , sqrt (vcov (m115f)[1,1]+1^2*vcov (m115f)[13,13]+2*1*vcov (m115f)[1,13])
       , sqrt (vcov (m115f)[1,1]+1^2*vcov (m115f)[12,12]+2*1*vcov (m115f)[1,12]))))

odd <- seq (1, nrow (coefMain02a)*2, by=2); even <- seq (2, nrow (coefMain02a)*2, by=2)
(coefMain02tab <- data.frame (rbind (coefMain02a, seMain02a))) ## warnings reported. Don't worry
rownames (coefMain02tab) <- c (odd, even)
coefMain02tab <- coefMain02tab[order (as.numeric (rownames (coefMain02tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", ""
           , "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (single party)", "", "no election (EAR)", "", "election (closed)", "", "election (single party)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m100a$N, length (unique (sum.m100a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m100a$fe$year.f)))
  , c (sum.m106a$N, length (unique (sum.m106a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m106a$fe$year.f)))
  , c (sum.m106b$N, length (unique (sum.m106b$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m106b$fe$year.f)))
  , c (sum.m107a$N, length (unique (sum.m107a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m107a$fe$year.f)))
  , c (sum.m107f$N, length (unique (sum.m107f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m107f$fe$year.f)))
  , c (sum.m114a$N, length (unique (sum.m114a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m114a$fe$year.f)))
  , c (sum.m115a$N, length (unique (sum.m115a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m115a$fe$year.f)))
  , c (sum.m115f$N, length (unique (sum.m115f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m115f$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} \\\\ \\midrule \n")
Header4 <- paste ("\\multicolumn{1}{l}{(a) \\emph{Closed, no elections}} & \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{11}{l}{(b) \\emph{EARs: Elections are formally competitive}} \\\\ \\midrule \n")
Header6 <- paste ("[2ex] \\multicolumn{11}{l}{(c) \\emph{Closed regimes with single-party elections}} \\\\ \\midrule \n")
Header7 <- paste ("[2ex] \\multicolumn{11}{l}{(d) \\emph{Control variables}} \\\\ \\midrule \n")
Header8 <- paste ("[2ex] \\multicolumn{11}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 2
addtorow$pos[[6]] <- 18
addtorow$pos[[7]] <- 34
addtorow$pos[[8]] <- 40
addtorow$pos[[9]] <- 52
addtorow$pos[[10]] <- 52
addtorow$pos[[11]] <- 52
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5, Header6, Header7, Header8
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefMain02tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Including competitive and non-competitive elections simultaneously"
               , label="T:rAllElections")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (2.3) Figure 2

# (2.3.1) Marginal effect of growth (t-1) on Pr (breakdown t):

# creating the dataset for the plots
dPlotMain01g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotMain01g) <- "dataset"
dPlotMain01g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotMain01g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotMain01g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotMain01g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotMain01g$estimate <- c (coefMain01tab[c (29, 33, 31, 35),5], coefMain01tab[c (29, 33, 31, 35),9]
                            , coefMain01tab[c (29, 33, 31, 35),6], coefMain01tab[c (29, 33, 31, 35),10]
                            , coefMain01tab[c (29, 33, 31, 35),12], coefMain01tab[c (29, 33, 31, 35),13]
                            , coefMain01tab[c (29, 33, 31, 35),15], coefMain01tab[c (29, 33, 31, 35),16])
dPlotMain01g$se <- c (coefMain01tab[c (29, 33, 31, 35)+1,5], coefMain01tab[c (29, 33, 31, 35)+1,9]
                      , coefMain01tab[c (29, 33, 31, 35)+1,6], coefMain01tab[c (29, 33, 31, 35)+1,10]
                      , coefMain01tab[c (29, 33, 31, 35)+1,12], coefMain01tab[c (29, 33, 31, 35)+1,13]
                      , coefMain01tab[c (29, 33, 31, 35)+1,15], coefMain01tab[c (29, 33, 31, 35)+1,16])
dPlotMain01g$ciLow <- with (dPlotMain01g, estimate + se*qt (0.025, df=n))
dPlotMain01g$ciHigh <- with (dPlotMain01g, estimate + se*qt (0.975, df=n))
dPlotMain01g <- dPlotMain01g[!is.na (dPlotMain01g$estimate),]
dPlotMain01g$effect <- factor (dPlotMain01g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (2.3.2) Marginal effect of election (t) on Pr (breakdown t):
dPlotMain01el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotMain01el) <- "dataset"
dPlotMain01el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotMain01el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotMain01el$growth <- rep (seq (min (maddMain$madddGDPHead_lag), max (maddMain$madddGDPHead_lag), length.out=m), 3)
dPlotMain01el$estimate <- with (dPlotMain01el, ifelse (
  elType=="actual elections\n(closed)", sum.m103a$coef[2,1]+sum.m103a$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m103a$coef[2,1]+sum.m103a$coef[7,1]+(sum.m103a$coef[3,1]+sum.m103a$coef[5,1])*growth, sum.m111a$coef[2,1]+sum.m111a$coef[4,1]*growth)))
dPlotMain01el$se <- with (dPlotMain01el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m103a)[2,2] + (growth^2)*vcov (m103a)[3,3] + (2*growth)*vcov (m103a)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m103a)[2,2] + (growth^2)*vcov (m103a)[3,3] + (1^2)*vcov (m103a)[7,7] + (growth^2)*(1^2)*vcov (m103a)[5,5] + (2*growth)*vcov (m103a)[2,3] + (2*1)*vcov (m103a)[2,7] + (2*growth*1)*vcov (m103a)[2,5] + (2*growth*1)*vcov (m103a)[3,7] + (2*1*growth^2)*vcov (m103a)[3,5] + (2*growth*1^2)*vcov (m103a)[7,5]), sqrt (vcov (m111a)[2,2] + (growth^2)*vcov (m111a)[4,4] + (2*growth)*vcov (m111a)[2,4]))))
dPlotMain01el$ciLow <- with (dPlotMain01el, estimate + se*qt (0.025, df=n))
dPlotMain01el$ciHigh <- with (dPlotMain01el, estimate + se*qt (0.975, df=n))
dPlotMain01el <- dPlotMain01el[abs (dPlotMain01el$growth) <= h.lim,]

# (2.3.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectMain01 <- ggplot (dPlotMain01g[dPlotMain01g$elType=="competitive\n& executive",]
                          , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectMain02 <- ggplot (dPlotMain01g[dPlotMain01g$controls=="no controls",]
                          , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthMain <- ggplot (maddMain[abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectMain03 <- ggplot (dPlotMain01el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthMain), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# (2.3.4) Exporting the plots
png ("Figures/fig_MainResults01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectMain01
dev.off ()
png ("Figures/fig_MainResults02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectMain02
dev.off ()
png ("Figures/fig_MainResults03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectMain03
dev.off ()

## (2.4) Figure A1

# (2.4.1) Marginal effect of growth (t-1) on Pr (breakdown t):

# creating the dataset for the plots
dPlotMain02g <- as.data.frame (factor (rep (c (rep ("actual elections", 6), rep ("scheduled elections", 6)), 2)))
colnames (dPlotMain02g) <- "dataset"
dPlotMain02g$controls <- factor (c (rep ("no controls", 12), rep ("w/controls", 12)))
dPlotMain02g$effect <- factor (rep (c ("closed\nnon-electoral", "single-party\nelectoral\n(no election)", "EAR\n(no election)", "closed\nnon-electoral\n(election)", "single-party\nelectoral\n(election)", "EAR\n(election)"), 4))

# marginal effect of growth and 95% CIs:
dPlotMain02g$n <- Ns00[1,c (rep (4, 6), rep (7, 6), rep (5, 6), rep (8, 6))]
dPlotMain02g$estimate <- c (coefMain02tab[c (41, 43, 45, 47, 49, 51),5], coefMain02tab[c (41, 43, 45, 47, 49, 51),9]
                            , coefMain02tab[c (41, 43, 45, 47, 49, 51),6], coefMain02tab[c (41, 43, 45, 47, 49, 51),10])
dPlotMain02g$se <- c (coefMain02tab[c (41, 43, 45, 47, 49, 51)+1,5], coefMain02tab[c (41, 43, 45, 47, 49, 51)+1,9]
                      , coefMain02tab[c (41, 43, 45, 47, 49, 51)+1,6], coefMain02tab[c (41, 43, 45, 47, 49, 51)+1,10])
dPlotMain02g$ciLow <- with (dPlotMain02g, estimate + se*qt (0.025, df=n))
dPlotMain02g$ciHigh <- with (dPlotMain02g, estimate + se*qt (0.975, df=n))
dPlotMain02g <- dPlotMain02g[!is.na (dPlotMain02g$estimate),]
dPlotMain02g$effect <- factor (dPlotMain02g$effect, levels=c ("closed\nnon-electoral", "single-party\nelectoral\n(no election)", "EAR\n(no election)", "closed\nnon-electoral\n(election)", "single-party\nelectoral\n(election)", "EAR\n(election)"), ordered=F)

# (2.4.2) Marginal effect of election (t) on Pr (breakdown t):
dPlotMain02el <- as.data.frame (factor (c (rep ("actual elections", m*4), rep ("scheduled elections", m*2))))
colnames (dPlotMain02el) <- "dataset"
dPlotMain02el$elType <- factor (c (rep ("actual elections\n(closed, SP electoral)", m), rep ("actual elections\n(closed, EAR)", m), rep ("actual elections\n(single-party electoral)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections\n(single-party electoral)", m), rep ("scheduled elections\n(EARs)", m)))
dPlotMain02el$n <- c (rep (Ns00[1,4], m*4) ,rep (Ns00[1,7], m*2))
dPlotMain02el$growth <- rep (seq (min (maddMain$madddGDPHead_lag), max (maddMain$madddGDPHead_lag), length.out=m), 6)
dPlotMain02el$estimate <- with (dPlotMain02el, ifelse (
  elType=="actual elections\n(closed, SP electoral)", sum.m107a$coef[8,1]+sum.m107a$coef[9,1]*growth, ifelse (
    elType=="actual elections\n(closed, EAR)", sum.m107a$coef[2,1]+sum.m107a$coef[3,1]*growth, ifelse (
      elType=="actual elections\n(single-party electoral)", sum.m107a$coef[8,1]+sum.m107a$coef[13,1]+(sum.m107a$coef[9,1]+sum.m107a$coef[11,1])*growth, ifelse (
        elType=="actual elections\n(EARs)", sum.m107a$coef[2,1]+sum.m107a$coef[7,1]+(sum.m107a$coef[3,1]+sum.m107a$coef[5,1])*growth, ifelse (
          elType=="scheduled elections\n(single-party electoral)", sum.m115a$coef[3,1]+sum.m115a$coef[10,1]*growth
          , sum.m115a$coef[2,1]+sum.m115a$coef[9,1]*growth))))))
dPlotMain02el$se <- with (dPlotMain02el, ifelse (
  elType=="actual elections\n(closed, SP electoral)", sqrt (vcov (m107a)[8,8] + (growth^2)*vcov (m107a)[9,9] + (2*growth)*vcov (m107a)[8,9]), ifelse (
    elType=="actual elections\n(closed, EAR)", sqrt (vcov (m107a)[2,2] + (growth^2)*vcov (m107a)[3,3] + (2*growth)*vcov (m107a)[2,3]), ifelse (
      elType=="actual elections\n(single-party electoral)", sqrt (vcov (m107a)[8,8] + (growth^2)*vcov (m107a)[9,9] + (1^2)*vcov (m107a)[13,13] + (growth^2)*(1^2)*vcov (m107a)[11,11] + (2*growth)*vcov (m107a)[8,9] + (2*1)*vcov (m107a)[8,13] + (2*growth*1)*vcov (m107a)[8,11] + (2*growth*1)*vcov (m107a)[9,13] + (2*1*growth^2)*vcov (m107a)[9,11] + (2*growth*1^2)*vcov (m107a)[13,11]), ifelse (
        elType=="actual elections\n(EARs)", sqrt (vcov (m107a)[2,2] + (growth^2)*vcov (m107a)[3,3] + (1^2)*vcov (m107a)[7,7] + (growth^2)*(1^2)*vcov (m107a)[5,5] + (2*growth)*vcov (m107a)[2,3] + (2*1)*vcov (m107a)[2,7] + (2*growth*1)*vcov (m107a)[2,5] + (2*growth*1)*vcov (m107a)[3,7] + (2*1*growth^2)*vcov (m107a)[3,5] + (2*growth*1^2)*vcov (m107a)[7,5]), ifelse (
          elType=="scheduled elections\n(single-party electoral)", sqrt (vcov (m115a)[3,3] + (growth^2)*vcov (m115a)[10,10] + (2*growth)*vcov (m115a)[3,10]), 
          sqrt (vcov (m115a)[2,2] + (growth^2)*vcov (m115a)[9,9] + (2*growth)*vcov (m115a)[2,9])))))))
dPlotMain02el$ciLow <- with (dPlotMain02el, estimate + se*qt (0.025, df=n))
dPlotMain02el$ciHigh <- with (dPlotMain02el, estimate + se*qt (0.975, df=n))
dPlotMain02el <- dPlotMain02el[abs (dPlotMain02el$growth) <= h.lim,]
dPlotMain02el$ear <- with (dPlotMain02el, ifelse (elType=="actual elections\n(closed, EAR)" | elType=="actual elections\n(EARs)" | elType=="scheduled elections\n(EARs)", 1, 0))

# (2.4.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectMainFull01 <- ggplot (dPlotMain02g, aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthMain <- ggplot (maddMain[abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth (single-party electoral)
(pEffectMainFull02 <- ggplot (dPlotMain02el[dPlotMain02el$ear==0,], aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthMain), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# Main results for elections|growth (EARs)
(pEffectMainFull03 <- ggplot (dPlotMain02el[dPlotMain02el$ear==1,], aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthMain), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# (2.4.4) Exporting the plots
png ("Figures/fig_MainResultsFull01.png", w=(plotWidth*1.35), h=(plotWidth*1.35)/aspect.ratio)
pEffectMainFull01
dev.off ()
png ("Figures/fig_MainResultsFull02.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectMainFull02
dev.off ()
png ("Figures/fig_MainResultsFull03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectMainFull03
dev.off ()



### (3) Alternative outcomes: Tables 2 and A8-A18 and Figures A2-A11

# (3.1) Table A8
(coefOutcome01a <- cbind (
  c (sum.m204a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m214a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m214c$coef[1:3,1], rep (NA, 6+5), sum.m214c$coef[1,1], sum.m214c$coef[1,1], sum.m214c$coef[1,1]+sum.m214c$coef[3,1], sum.m214c$coef[1,1]+sum.m214c$coef[3,1])
  , c (sum.m214e$coef[1:7,1], rep (NA, 2+5), sum.m214e$coef[1,1], sum.m214e$coef[1,1]+sum.m214e$coef[4,1], sum.m214e$coef[1,1]+sum.m214e$coef[3,1], sum.m214e$coef[1,1]+sum.m214e$coef[3,1]+sum.m214e$coef[4,1]+sum.m214e$coef[5,1])
  , c (sum.m214f$coef[1:7,1], rep (NA, 2+2), sum.m214f$coef[8:10,1], sum.m214f$coef[1,1], sum.m214f$coef[1,1]+sum.m214f$coef[4,1], sum.m214f$coef[1,1]+sum.m214f$coef[3,1], sum.m214f$coef[1,1]+sum.m214f$coef[3,1]+sum.m214f$coef[4,1]+sum.m214f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m224a$coef[1,1], rep (NA, 5), sum.m224a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m224e$coef[c (1:2,4),1], rep (NA, 4), sum.m224e$coef[c (3,5),1], rep (NA, 5), sum.m224e$coef[1,1], sum.m224e$coef[1,1]+sum.m224e$coef[5,1], NA, sum.m224e$coef[1,1]+sum.m224e$coef[4,1])
  , c (sum.m224f$coef[c (1:2,4),1], rep (NA, 4), sum.m224f$coef[c (3,5),1], rep (NA, 2), sum.m224f$coef[6:8,1], sum.m224f$coef[1,1], sum.m224f$coef[1,1]+sum.m224f$coef[5,1], NA, sum.m224f$coef[1,1]+sum.m224f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m214g$coef[1:7,1], rep (NA, 2+5), sum.m214g$coef[1,1], sum.m214g$coef[1,1]+sum.m214g$coef[4,1], sum.m214g$coef[1,1]+sum.m214g$coef[3,1], sum.m214g$coef[1,1]+sum.m214g$coef[3,1]+sum.m214g$coef[4,1]+sum.m214g$coef[5,1])
  , c (sum.m224g$coef[c (1:2,4),1], rep (NA, 4), sum.m224g$coef[c (3,5),1], rep (NA, 5), sum.m224g$coef[1,1], sum.m224g$coef[1,1]+sum.m224g$coef[5,1], NA, sum.m224g$coef[1,1]+sum.m224g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m214i$coef[1:7,1], rep (NA, 2+5), sum.m214i$coef[1,1], sum.m214i$coef[1,1]+sum.m214i$coef[4,1], sum.m214i$coef[1,1]+sum.m214i$coef[3,1], sum.m214i$coef[1,1]+sum.m214i$coef[3,1]+sum.m214i$coef[4,1]+sum.m214i$coef[5,1])
  , c (sum.m224i$coef[c (1:2,4),1], rep (NA, 4), sum.m224i$coef[c (3,5:7),1], rep (NA, 3), sum.m224i$coef[1,1], sum.m224i$coef[1,1]+sum.m224i$coef[5,1], NA, sum.m224i$coef[1,1]+sum.m224i$coef[4,1])))
(seOutcome01a <- cbind (
  c (sum.m204a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m214a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m214c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m214c)[1,1])
       , sqrt (vcov (m214c)[1,1])
       , sqrt (vcov (m214c)[1,1]+1^2*vcov (m214c)[3,3]+2*1*vcov (m214c)[1,3])
       , sqrt (vcov (m214c)[1,1]+1^2*vcov (m214c)[3,3]+2*1*vcov (m214c)[1,3]))
  , c (sum.m214e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m214e)[1,1])
       , sqrt (vcov (m214e)[1,1]+1^2*vcov (m214e)[4,4]+2*1*vcov (m214e)[1,4])
       , sqrt (vcov (m214e)[1,1]+1^2*vcov (m214e)[3,3]+2*1*vcov (m214e)[1,3])
       , sqrt (vcov (m214e)[1,1]+1^2*vcov (m214e)[3,3]+1^2*vcov (m214e)[4,4]+1^2*1^2*vcov (m214e)[5,5]+2*1*vcov (m214e)[1,3]+2*1*vcov (m214e)[1,4]+2*1*1*vcov (m214e)[1,5]+2*1*1*vcov (m214e)[3,4]+2*1*1^2*vcov (m214e)[3,5]+2*1*1^2*vcov (m214e)[4,5]))
  , c (sum.m214f$coef[1:7,2], rep (NA, 2+2), sum.m214f$coef[8:10,2]
       , sqrt (vcov (m214f)[1,1])
       , sqrt (vcov (m214f)[1,1]+1^2*vcov (m214f)[4,4]+2*1*vcov (m214f)[1,4])
       , sqrt (vcov (m214f)[1,1]+1^2*vcov (m214f)[3,3]+2*1*vcov (m214f)[1,3])
       , sqrt (vcov (m214f)[1,1]+1^2*vcov (m214f)[3,3]+1^2*vcov (m214f)[4,4]+1^2*1^2*vcov (m214f)[5,5]+2*1*vcov (m214f)[1,3]+2*1*vcov (m214f)[1,4]+2*1*1*vcov (m214f)[1,5]+2*1*1*vcov (m214f)[3,4]+2*1*1^2*vcov (m214f)[3,5]+2*1*1^2*vcov (m214f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m224a$coef[1,2], rep (NA, 5), sum.m224a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m224e$coef[c (1:2,4),2], rep (NA, 4), sum.m224e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m224e)[1,1])
       , sqrt (vcov (m224e)[1,1]+1^2*vcov (m224e)[5,5]+2*1*vcov (m224e)[1,5])
       , NA
       , sqrt (vcov (m224e)[1,1]+1^2*vcov (m224e)[4,4]+2*1*vcov (m224e)[1,4]))
  , c (sum.m224f$coef[c (1:2,4),2], rep (NA, 4), sum.m224f$coef[c (3,5),2], rep (NA, 2), sum.m224f$coef[6:8,2]
       , sqrt (vcov (m224f)[1,1])
       , sqrt (vcov (m224f)[1,1]+1^2*vcov (m224f)[5,5]+2*1*vcov (m224f)[1,5])
       , NA
       , sqrt (vcov (m224f)[1,1]+1^2*vcov (m224f)[4,4]+2*1*vcov (m224f)[1,4]))
  , rep (NA, 18)
  , c (sum.m214g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m214g)[1,1])
       , sqrt (vcov (m214g)[1,1]+1^2*vcov (m214g)[4,4]+2*1*vcov (m214g)[1,4])
       , sqrt (vcov (m214g)[1,1]+1^2*vcov (m214g)[3,3]+2*1*vcov (m214g)[1,3])
       , sqrt (vcov (m214g)[1,1]+1^2*vcov (m214g)[3,3]+1^2*vcov (m214g)[4,4]+1^2*1^2*vcov (m214g)[5,5]+2*1*vcov (m214g)[1,3]+2*1*vcov (m214g)[1,4]+2*1*1*vcov (m214g)[1,5]+2*1*1*vcov (m214g)[3,4]+2*1*1^2*vcov (m214g)[3,5]+2*1*1^2*vcov (m214g)[4,5]))
  , c (sum.m224g$coef[c (1:2,4),2], rep (NA, 4), sum.m224g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m224g)[1,1])
       , sqrt (vcov (m224g)[1,1]+1^2*vcov (m224g)[5,5]+2*1*vcov (m224g)[1,5])
       , NA
       , sqrt (vcov (m224g)[1,1]+1^2*vcov (m224g)[4,4]+2*1*vcov (m224g)[1,4]))
  , rep (NA, 18)
  , c (sum.m214i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m214i)[1,1])
       , sqrt (vcov (m214i)[1,1]+1^2*vcov (m214i)[4,4]+2*1*vcov (m214i)[1,4])
       , sqrt (vcov (m214i)[1,1]+1^2*vcov (m214i)[3,3]+2*1*vcov (m214i)[1,3])
       , sqrt (vcov (m214i)[1,1]+1^2*vcov (m214i)[3,3]+1^2*vcov (m214i)[4,4]+1^2*1^2*vcov (m214i)[5,5]+2*1*vcov (m214i)[1,3]+2*1*vcov (m214i)[1,4]+2*1*1*vcov (m214i)[1,5]+2*1*1*vcov (m214i)[3,4]+2*1*1^2*vcov (m214i)[3,5]+2*1*1^2*vcov (m214i)[4,5]))
  , c (sum.m224i$coef[c (1:2,4),2], rep (NA, 4), sum.m224i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m224i)[1,1])
       , sqrt (vcov (m224i)[1,1]+1^2*vcov (m224i)[5,5]+2*1*vcov (m224i)[1,5])
       , NA
       , sqrt (vcov (m224i)[1,1]+1^2*vcov (m224i)[4,4]+2*1*vcov (m224i)[1,4]))))

odd <- seq (1, nrow (coefOutcome01a)*2, by=2); even <- seq (2, nrow (coefOutcome01a)*2, by=2)
(coefOutcome01tab <- data.frame (rbind (coefOutcome01a, seOutcome01a))) ## warnings reported. Don't worry
rownames (coefOutcome01tab) <- c (odd, even)
coefOutcome01tab <- coefOutcome01tab[order (as.numeric (rownames (coefOutcome01tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m204a$N, length (unique (sum.m204a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m204a$fe$year.f)))
  , c (sum.m214a$N, length (unique (sum.m214a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m214a$fe$year.f)))
  , c (sum.m214c$N, length (unique (sum.m214c$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m214c$fe$year.f)))
  , c (sum.m214e$N, length (unique (sum.m214e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m214e$fe$year.f)))
  , c (sum.m214f$N, length (unique (sum.m214f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m214f$fe$year.f)))
  , c (sum.m224a$N, length (unique (sum.m224a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m224a$fe$year.f)))
  , c (sum.m224e$N, length (unique (sum.m224e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m224e$fe$year.f)))
  , c (sum.m224f$N, length (unique (sum.m224f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m224f$fe$year.f)))
  , c (sum.m214g$N, length (unique (sum.m214g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m214g$fe$year.f)))
  , c (sum.m224g$N, length (unique (sum.m224g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m224g$fe$year.f)))
  , c (sum.m214i$N, length (unique (sum.m214i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m214i$fe$year.f)))
  , c (sum.m224i$N, length (unique (sum.m224i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m224i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (end (insider)_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefOutcome01tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Alternative Outcomes (1): Insider-driven end"
               , label="T:rOutcomeInsider")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (3.1.2) Figure A2

# (3.1.2.1) Marginal effect of growth (t-1) on Pr (insider end t):

# creating the dataset for the plots
dPlotOutcome01g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotOutcome01g) <- "dataset"
dPlotOutcome01g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotOutcome01g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotOutcome01g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotOutcome01g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotOutcome01g$estimate <- c (coefOutcome01tab[c (29, 33, 31, 35),5], coefOutcome01tab[c (29, 33, 31, 35),9]
                               , coefOutcome01tab[c (29, 33, 31, 35),6], coefOutcome01tab[c (29, 33, 31, 35),10]
                               , coefOutcome01tab[c (29, 33, 31, 35),12], coefOutcome01tab[c (29, 33, 31, 35),13]
                               , coefOutcome01tab[c (29, 33, 31, 35),15], coefOutcome01tab[c (29, 33, 31, 35),16])
dPlotOutcome01g$se <- c (coefOutcome01tab[c (29, 33, 31, 35)+1,5], coefOutcome01tab[c (29, 33, 31, 35)+1,9]
                         , coefOutcome01tab[c (29, 33, 31, 35)+1,6], coefOutcome01tab[c (29, 33, 31, 35)+1,10]
                         , coefOutcome01tab[c (29, 33, 31, 35)+1,12], coefOutcome01tab[c (29, 33, 31, 35)+1,13]
                         , coefOutcome01tab[c (29, 33, 31, 35)+1,15], coefOutcome01tab[c (29, 33, 31, 35)+1,16])
dPlotOutcome01g$ciLow <- with (dPlotOutcome01g, estimate + se*qt (0.025, df=n))
dPlotOutcome01g$ciHigh <- with (dPlotOutcome01g, estimate + se*qt (0.975, df=n))
dPlotOutcome01g <- dPlotOutcome01g[!is.na (dPlotOutcome01g$estimate),]
dPlotOutcome01g$effect <- factor (dPlotOutcome01g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (3.1.2.2) Marginal effect of election (t) on Pr (insider end t):
dPlotOutcome01el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotOutcome01el) <- "dataset"
dPlotOutcome01el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotOutcome01el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotOutcome01el$growth <- rep (seq (min (maddMain$madddGDPHead_lag), max (maddMain$madddGDPHead_lag), length.out=m), 3)
dPlotOutcome01el$estimate <- with (dPlotOutcome01el, ifelse (
  elType=="actual elections\n(closed)", sum.m214e$coef[2,1]+sum.m214e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m214e$coef[2,1]+sum.m214e$coef[7,1]+(sum.m214e$coef[3,1]+sum.m214e$coef[5,1])*growth, sum.m224e$coef[2,1]+sum.m224e$coef[4,1]*growth)))
dPlotOutcome01el$se <- with (dPlotOutcome01el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m214e)[2,2] + (growth^2)*vcov (m214e)[3,3] + (2*growth)*vcov (m214e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m214e)[2,2] + (growth^2)*vcov (m214e)[3,3] + (1^2)*vcov (m214e)[7,7] + (growth^2)*(1^2)*vcov (m214e)[5,5] + (2*growth)*vcov (m214e)[2,3] + (2*1)*vcov (m214e)[2,7] + (2*growth*1)*vcov (m214e)[2,5] + (2*growth*1)*vcov (m214e)[3,7] + (2*1*growth^2)*vcov (m214e)[3,5] + (2*growth*1^2)*vcov (m214e)[7,5]), sqrt (vcov (m224e)[2,2] + (growth^2)*vcov (m224e)[4,4] + (2*growth)*vcov (m224e)[2,4]))))
dPlotOutcome01el$ciLow <- with (dPlotOutcome01el, estimate + se*qt (0.025, df=n))
dPlotOutcome01el$ciHigh <- with (dPlotOutcome01el, estimate + se*qt (0.975, df=n))
dPlotOutcome01el <- dPlotOutcome01el[abs (dPlotOutcome01el$growth) <= h.lim,]

# (3.1.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectOutcomeInsider01 <- ggplot (dPlotOutcome01g[dPlotOutcome01g$elType=="competitive\n& executive",]
                                    , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[end (insider) (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectOutcomeInsider02 <- ggplot (dPlotOutcome01g[dPlotOutcome01g$controls=="no controls",]
                                    , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[end (insider) (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthOutcomeInsider <- ggplot (maddMain[abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectOutcomeInsider03 <- ggplot (dPlotOutcome01el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthOutcomeInsider), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[end (insider) (t)]"))

# (3.1.2.4) Exporting the plots
png ("Figures/fig_rOutcomeInsider01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeInsider01
dev.off ()
png ("Figures/fig_rOutcomeInsider02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeInsider02
dev.off ()
png ("Figures/fig_rOutcomeInsider03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectOutcomeInsider03
dev.off ()


## (3.2) Table A9
(coefOutcome02a <- cbind (
  c (sum.m205a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m215a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m215c$coef[1:3,1], rep (NA, 6+5), sum.m215c$coef[1,1], sum.m215c$coef[1,1], sum.m215c$coef[1,1]+sum.m215c$coef[3,1], sum.m215c$coef[1,1]+sum.m215c$coef[3,1])
  , c (sum.m215e$coef[1:7,1], rep (NA, 2+5), sum.m215e$coef[1,1], sum.m215e$coef[1,1]+sum.m215e$coef[4,1], sum.m215e$coef[1,1]+sum.m215e$coef[3,1], sum.m215e$coef[1,1]+sum.m215e$coef[3,1]+sum.m215e$coef[4,1]+sum.m215e$coef[5,1])
  , c (sum.m215f$coef[1:7,1], rep (NA, 2+2), sum.m215f$coef[8:10,1], sum.m215f$coef[1,1], sum.m215f$coef[1,1]+sum.m215f$coef[4,1], sum.m215f$coef[1,1]+sum.m215f$coef[3,1], sum.m215f$coef[1,1]+sum.m215f$coef[3,1]+sum.m215f$coef[4,1]+sum.m215f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m225a$coef[1,1], rep (NA, 5), sum.m225a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m225e$coef[c (1:2,4),1], rep (NA, 4), sum.m225e$coef[c (3,5),1], rep (NA, 5), sum.m225e$coef[1,1], sum.m225e$coef[1,1]+sum.m225e$coef[5,1], NA, sum.m225e$coef[1,1]+sum.m225e$coef[4,1])
  , c (sum.m225f$coef[c (1:2,4),1], rep (NA, 4), sum.m225f$coef[c (3,5),1], rep (NA, 2), sum.m225f$coef[6:8,1], sum.m225f$coef[1,1], sum.m225f$coef[1,1]+sum.m225f$coef[5,1], NA, sum.m225f$coef[1,1]+sum.m225f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m215g$coef[1:7,1], rep (NA, 2+5), sum.m215g$coef[1,1], sum.m215g$coef[1,1]+sum.m215g$coef[4,1], sum.m215g$coef[1,1]+sum.m215g$coef[3,1], sum.m215g$coef[1,1]+sum.m215g$coef[3,1]+sum.m215g$coef[4,1]+sum.m215g$coef[5,1])
  , c (sum.m225g$coef[c (1:2,4),1], rep (NA, 4), sum.m225g$coef[c (3,5),1], rep (NA, 5), sum.m225g$coef[1,1], sum.m225g$coef[1,1]+sum.m225g$coef[5,1], NA, sum.m225g$coef[1,1]+sum.m225g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m215i$coef[1:7,1], rep (NA, 2+5), sum.m215i$coef[1,1], sum.m215i$coef[1,1]+sum.m215i$coef[4,1], sum.m215i$coef[1,1]+sum.m215i$coef[3,1], sum.m215i$coef[1,1]+sum.m215i$coef[3,1]+sum.m215i$coef[4,1]+sum.m215i$coef[5,1])
  , c (sum.m225i$coef[c (1:2,4),1], rep (NA, 4), sum.m225i$coef[c (3,5:7),1], rep (NA, 3), sum.m225i$coef[1,1], sum.m225i$coef[1,1]+sum.m225i$coef[5,1], NA, sum.m225i$coef[1,1]+sum.m225i$coef[4,1])))
(seOutcome02a <- cbind (
  c (sum.m205a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m215a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m215c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m215c)[1,1])
       , sqrt (vcov (m215c)[1,1])
       , sqrt (vcov (m215c)[1,1]+1^2*vcov (m215c)[3,3]+2*1*vcov (m215c)[1,3])
       , sqrt (vcov (m215c)[1,1]+1^2*vcov (m215c)[3,3]+2*1*vcov (m215c)[1,3]))
  , c (sum.m215e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m215e)[1,1])
       , sqrt (vcov (m215e)[1,1]+1^2*vcov (m215e)[4,4]+2*1*vcov (m215e)[1,4])
       , sqrt (vcov (m215e)[1,1]+1^2*vcov (m215e)[3,3]+2*1*vcov (m215e)[1,3])
       , sqrt (vcov (m215e)[1,1]+1^2*vcov (m215e)[3,3]+1^2*vcov (m215e)[4,4]+1^2*1^2*vcov (m215e)[5,5]+2*1*vcov (m215e)[1,3]+2*1*vcov (m215e)[1,4]+2*1*1*vcov (m215e)[1,5]+2*1*1*vcov (m215e)[3,4]+2*1*1^2*vcov (m215e)[3,5]+2*1*1^2*vcov (m215e)[4,5]))
  , c (sum.m215f$coef[1:7,2], rep (NA, 2+2), sum.m215f$coef[8:10,2]
       , sqrt (vcov (m215f)[1,1])
       , sqrt (vcov (m215f)[1,1]+1^2*vcov (m215f)[4,4]+2*1*vcov (m215f)[1,4])
       , sqrt (vcov (m215f)[1,1]+1^2*vcov (m215f)[3,3]+2*1*vcov (m215f)[1,3])
       , sqrt (vcov (m215f)[1,1]+1^2*vcov (m215f)[3,3]+1^2*vcov (m215f)[4,4]+1^2*1^2*vcov (m215f)[5,5]+2*1*vcov (m215f)[1,3]+2*1*vcov (m215f)[1,4]+2*1*1*vcov (m215f)[1,5]+2*1*1*vcov (m215f)[3,4]+2*1*1^2*vcov (m215f)[3,5]+2*1*1^2*vcov (m215f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m225a$coef[1,2], rep (NA, 5), sum.m225a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m225e$coef[c (1:2,4),2], rep (NA, 4), sum.m225e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m225e)[1,1])
       , sqrt (vcov (m225e)[1,1]+1^2*vcov (m225e)[5,5]+2*1*vcov (m225e)[1,5])
       , NA
       , sqrt (vcov (m225e)[1,1]+1^2*vcov (m225e)[4,4]+2*1*vcov (m225e)[1,4]))
  , c (sum.m225f$coef[c (1:2,4),2], rep (NA, 4), sum.m225f$coef[c (3,5),2], rep (NA, 2), sum.m225f$coef[6:8,2]
       , sqrt (vcov (m225f)[1,1])
       , sqrt (vcov (m225f)[1,1]+1^2*vcov (m225f)[5,5]+2*1*vcov (m225f)[1,5])
       , NA
       , sqrt (vcov (m225f)[1,1]+1^2*vcov (m225f)[4,4]+2*1*vcov (m225f)[1,4]))
  , rep (NA, 18)
  , c (sum.m215g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m215g)[1,1])
       , sqrt (vcov (m215g)[1,1]+1^2*vcov (m215g)[4,4]+2*1*vcov (m215g)[1,4])
       , sqrt (vcov (m215g)[1,1]+1^2*vcov (m215g)[3,3]+2*1*vcov (m215g)[1,3])
       , sqrt (vcov (m215g)[1,1]+1^2*vcov (m215g)[3,3]+1^2*vcov (m215g)[4,4]+1^2*1^2*vcov (m215g)[5,5]+2*1*vcov (m215g)[1,3]+2*1*vcov (m215g)[1,4]+2*1*1*vcov (m215g)[1,5]+2*1*1*vcov (m215g)[3,4]+2*1*1^2*vcov (m215g)[3,5]+2*1*1^2*vcov (m215g)[4,5]))
  , c (sum.m225g$coef[c (1:2,4),2], rep (NA, 4), sum.m225g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m225g)[1,1])
       , sqrt (vcov (m225g)[1,1]+1^2*vcov (m225g)[5,5]+2*1*vcov (m225g)[1,5])
       , NA
       , sqrt (vcov (m225g)[1,1]+1^2*vcov (m225g)[4,4]+2*1*vcov (m225g)[1,4]))
  , rep (NA, 18)
  , c (sum.m215i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m215i)[1,1])
       , sqrt (vcov (m215i)[1,1]+1^2*vcov (m215i)[4,4]+2*1*vcov (m215i)[1,4])
       , sqrt (vcov (m215i)[1,1]+1^2*vcov (m215i)[3,3]+2*1*vcov (m215i)[1,3])
       , sqrt (vcov (m215i)[1,1]+1^2*vcov (m215i)[3,3]+1^2*vcov (m215i)[4,4]+1^2*1^2*vcov (m215i)[5,5]+2*1*vcov (m215i)[1,3]+2*1*vcov (m215i)[1,4]+2*1*1*vcov (m215i)[1,5]+2*1*1*vcov (m215i)[3,4]+2*1*1^2*vcov (m215i)[3,5]+2*1*1^2*vcov (m215i)[4,5]))
  , c (sum.m225i$coef[c (1:2,4),2], rep (NA, 4), sum.m225i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m225i)[1,1])
       , sqrt (vcov (m225i)[1,1]+1^2*vcov (m225i)[5,5]+2*1*vcov (m225i)[1,5])
       , NA
       , sqrt (vcov (m225i)[1,1]+1^2*vcov (m225i)[4,4]+2*1*vcov (m225i)[1,4]))))

odd <- seq (1, nrow (coefOutcome02a)*2, by=2); even <- seq (2, nrow (coefOutcome02a)*2, by=2)
(coefOutcome02tab <- data.frame (rbind (coefOutcome02a, seOutcome02a))) ## warnings reported. Don't worry
rownames (coefOutcome02tab) <- c (odd, even)
coefOutcome02tab <- coefOutcome02tab[order (as.numeric (rownames (coefOutcome02tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m205a$N, length (unique (sum.m205a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m205a$fe$year.f)))
  , c (sum.m215a$N, length (unique (sum.m215a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m215a$fe$year.f)))
  , c (sum.m215c$N, length (unique (sum.m215c$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m215c$fe$year.f)))
  , c (sum.m215e$N, length (unique (sum.m215e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m215e$fe$year.f)))
  , c (sum.m215f$N, length (unique (sum.m215f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m215f$fe$year.f)))
  , c (sum.m225a$N, length (unique (sum.m225a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m225a$fe$year.f)))
  , c (sum.m225e$N, length (unique (sum.m225e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m225e$fe$year.f)))
  , c (sum.m225f$N, length (unique (sum.m225f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m225f$fe$year.f)))
  , c (sum.m215g$N, length (unique (sum.m215g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m215g$fe$year.f)))
  , c (sum.m225g$N, length (unique (sum.m225g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m225g$fe$year.f)))
  , c (sum.m215i$N, length (unique (sum.m215i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m215i$fe$year.f)))
  , c (sum.m225i$N, length (unique (sum.m225i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m225i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (end (outsider)_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefOutcome02tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Alternative Outcomes (2): Outsider-driven end"
               , label="T:rOutcomeOutsider")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (3.2.2) Figure A3

# (3.2.2.1) Marginal effect of growth (t-1) on Pr (outsider end t):

# creating the dataset for the plots
dPlotOutcome02g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotOutcome02g) <- "dataset"
dPlotOutcome02g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotOutcome02g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotOutcome02g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotOutcome02g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotOutcome02g$estimate <- c (coefOutcome02tab[c (29, 33, 31, 35),5], coefOutcome02tab[c (29, 33, 31, 35),9]
                               , coefOutcome02tab[c (29, 33, 31, 35),6], coefOutcome02tab[c (29, 33, 31, 35),10]
                               , coefOutcome02tab[c (29, 33, 31, 35),12], coefOutcome02tab[c (29, 33, 31, 35),13]
                               , coefOutcome02tab[c (29, 33, 31, 35),15], coefOutcome02tab[c (29, 33, 31, 35),16])
dPlotOutcome02g$se <- c (coefOutcome02tab[c (29, 33, 31, 35)+1,5], coefOutcome02tab[c (29, 33, 31, 35)+1,9]
                         , coefOutcome02tab[c (29, 33, 31, 35)+1,6], coefOutcome02tab[c (29, 33, 31, 35)+1,10]
                         , coefOutcome02tab[c (29, 33, 31, 35)+1,12], coefOutcome02tab[c (29, 33, 31, 35)+1,13]
                         , coefOutcome02tab[c (29, 33, 31, 35)+1,15], coefOutcome02tab[c (29, 33, 31, 35)+1,16])
dPlotOutcome02g$ciLow <- with (dPlotOutcome02g, estimate + se*qt (0.025, df=n))
dPlotOutcome02g$ciHigh <- with (dPlotOutcome02g, estimate + se*qt (0.975, df=n))
dPlotOutcome02g <- dPlotOutcome02g[!is.na (dPlotOutcome02g$estimate),]
dPlotOutcome02g$effect <- factor (dPlotOutcome02g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (3.2.2.2) Marginal effect of election (t) on Pr (outsider end t):
dPlotOutcome02el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotOutcome02el) <- "dataset"
dPlotOutcome02el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotOutcome02el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotOutcome02el$growth <- rep (seq (min (maddMain$madddGDPHead_lag), max (maddMain$madddGDPHead_lag), length.out=m), 3)
dPlotOutcome02el$estimate <- with (dPlotOutcome02el, ifelse (
  elType=="actual elections\n(closed)", sum.m215e$coef[2,1]+sum.m215e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m215e$coef[2,1]+sum.m215e$coef[7,1]+(sum.m215e$coef[3,1]+sum.m215e$coef[5,1])*growth, sum.m225e$coef[2,1]+sum.m225e$coef[4,1]*growth)))
dPlotOutcome02el$se <- with (dPlotOutcome02el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m215e)[2,2] + (growth^2)*vcov (m215e)[3,3] + (2*growth)*vcov (m215e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m215e)[2,2] + (growth^2)*vcov (m215e)[3,3] + (1^2)*vcov (m215e)[7,7] + (growth^2)*(1^2)*vcov (m215e)[5,5] + (2*growth)*vcov (m215e)[2,3] + (2*1)*vcov (m215e)[2,7] + (2*growth*1)*vcov (m215e)[2,5] + (2*growth*1)*vcov (m215e)[3,7] + (2*1*growth^2)*vcov (m215e)[3,5] + (2*growth*1^2)*vcov (m215e)[7,5]), sqrt (vcov (m225e)[2,2] + (growth^2)*vcov (m225e)[4,4] + (2*growth)*vcov (m225e)[2,4]))))
dPlotOutcome02el$ciLow <- with (dPlotOutcome02el, estimate + se*qt (0.025, df=n))
dPlotOutcome02el$ciHigh <- with (dPlotOutcome02el, estimate + se*qt (0.975, df=n))
dPlotOutcome02el <- dPlotOutcome02el[abs (dPlotOutcome02el$growth) <= h.lim,]

# (3.2.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectOutcomeOutsider01 <- ggplot (dPlotOutcome02g[dPlotOutcome02g$elType=="competitive\n& executive",]
                                     , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[end (outsider) (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectOutcomeOutsider02 <- ggplot (dPlotOutcome02g[dPlotOutcome02g$controls=="no controls",]
                                     , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[end (outsider) (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthOutcomeOutsider <- ggplot (maddMain[abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectOutcomeOutsider03 <- ggplot (dPlotOutcome02el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthOutcomeOutsider), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[end (outsider) (t)]"))

# (3.2.2.4) Exporting the plots
png ("Figures/fig_rOutcomeOutsider01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeOutsider01
dev.off ()
png ("Figures/fig_rOutcomeOutsider02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeOutsider02
dev.off ()
png ("Figures/fig_rOutcomeOutsider03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectOutcomeOutsider03
dev.off ()


## (3.3) Table A10
(coefOutcome03a <- cbind (
  c (sum.m206a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m216a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m216c$coef[1:3,1], rep (NA, 6+5), sum.m216c$coef[1,1], sum.m216c$coef[1,1], sum.m216c$coef[1,1]+sum.m216c$coef[3,1], sum.m216c$coef[1,1]+sum.m216c$coef[3,1])
  , c (sum.m216e$coef[1:7,1], rep (NA, 2+5), sum.m216e$coef[1,1], sum.m216e$coef[1,1]+sum.m216e$coef[4,1], sum.m216e$coef[1,1]+sum.m216e$coef[3,1], sum.m216e$coef[1,1]+sum.m216e$coef[3,1]+sum.m216e$coef[4,1]+sum.m216e$coef[5,1])
  , c (sum.m216f$coef[1:7,1], rep (NA, 2+2), sum.m216f$coef[8:10,1], sum.m216f$coef[1,1], sum.m216f$coef[1,1]+sum.m216f$coef[4,1], sum.m216f$coef[1,1]+sum.m216f$coef[3,1], sum.m216f$coef[1,1]+sum.m216f$coef[3,1]+sum.m216f$coef[4,1]+sum.m216f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m226a$coef[1,1], rep (NA, 5), sum.m226a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m226e$coef[c (1:2,4),1], rep (NA, 4), sum.m226e$coef[c (3,5),1], rep (NA, 5), sum.m226e$coef[1,1], sum.m226e$coef[1,1]+sum.m226e$coef[5,1], NA, sum.m226e$coef[1,1]+sum.m226e$coef[4,1])
  , c (sum.m226f$coef[c (1:2,4),1], rep (NA, 4), sum.m226f$coef[c (3,5),1], rep (NA, 2), sum.m226f$coef[6:8,1], sum.m226f$coef[1,1], sum.m226f$coef[1,1]+sum.m226f$coef[5,1], NA, sum.m226f$coef[1,1]+sum.m226f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m216g$coef[1:7,1], rep (NA, 2+5), sum.m216g$coef[1,1], sum.m216g$coef[1,1]+sum.m216g$coef[4,1], sum.m216g$coef[1,1]+sum.m216g$coef[3,1], sum.m216g$coef[1,1]+sum.m216g$coef[3,1]+sum.m216g$coef[4,1]+sum.m216g$coef[5,1])
  , c (sum.m226g$coef[c (1:2,4),1], rep (NA, 4), sum.m226g$coef[c (3,5),1], rep (NA, 5), sum.m226g$coef[1,1], sum.m226g$coef[1,1]+sum.m226g$coef[5,1], NA, sum.m226g$coef[1,1]+sum.m226g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m216i$coef[1:7,1], rep (NA, 2+5), sum.m216i$coef[1,1], sum.m216i$coef[1,1]+sum.m216i$coef[4,1], sum.m216i$coef[1,1]+sum.m216i$coef[3,1], sum.m216i$coef[1,1]+sum.m216i$coef[3,1]+sum.m216i$coef[4,1]+sum.m216i$coef[5,1])
  , c (sum.m226i$coef[c (1:2,4),1], rep (NA, 4), sum.m226i$coef[c (3,5:7),1], rep (NA, 3), sum.m226i$coef[1,1], sum.m226i$coef[1,1]+sum.m226i$coef[5,1], NA, sum.m226i$coef[1,1]+sum.m226i$coef[4,1])))
(seOutcome03a <- cbind (
  c (sum.m206a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m216a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m216c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m216c)[1,1])
       , sqrt (vcov (m216c)[1,1])
       , sqrt (vcov (m216c)[1,1]+1^2*vcov (m216c)[3,3]+2*1*vcov (m216c)[1,3])
       , sqrt (vcov (m216c)[1,1]+1^2*vcov (m216c)[3,3]+2*1*vcov (m216c)[1,3]))
  , c (sum.m216e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m216e)[1,1])
       , sqrt (vcov (m216e)[1,1]+1^2*vcov (m216e)[4,4]+2*1*vcov (m216e)[1,4])
       , sqrt (vcov (m216e)[1,1]+1^2*vcov (m216e)[3,3]+2*1*vcov (m216e)[1,3])
       , sqrt (vcov (m216e)[1,1]+1^2*vcov (m216e)[3,3]+1^2*vcov (m216e)[4,4]+1^2*1^2*vcov (m216e)[5,5]+2*1*vcov (m216e)[1,3]+2*1*vcov (m216e)[1,4]+2*1*1*vcov (m216e)[1,5]+2*1*1*vcov (m216e)[3,4]+2*1*1^2*vcov (m216e)[3,5]+2*1*1^2*vcov (m216e)[4,5]))
  , c (sum.m216f$coef[1:7,2], rep (NA, 2+2), sum.m216f$coef[8:10,2]
       , sqrt (vcov (m216f)[1,1])
       , sqrt (vcov (m216f)[1,1]+1^2*vcov (m216f)[4,4]+2*1*vcov (m216f)[1,4])
       , sqrt (vcov (m216f)[1,1]+1^2*vcov (m216f)[3,3]+2*1*vcov (m216f)[1,3])
       , sqrt (vcov (m216f)[1,1]+1^2*vcov (m216f)[3,3]+1^2*vcov (m216f)[4,4]+1^2*1^2*vcov (m216f)[5,5]+2*1*vcov (m216f)[1,3]+2*1*vcov (m216f)[1,4]+2*1*1*vcov (m216f)[1,5]+2*1*1*vcov (m216f)[3,4]+2*1*1^2*vcov (m216f)[3,5]+2*1*1^2*vcov (m216f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m226a$coef[1,2], rep (NA, 5), sum.m226a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m226e$coef[c (1:2,4),2], rep (NA, 4), sum.m226e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m226e)[1,1])
       , sqrt (vcov (m226e)[1,1]+1^2*vcov (m226e)[5,5]+2*1*vcov (m226e)[1,5])
       , NA
       , sqrt (vcov (m226e)[1,1]+1^2*vcov (m226e)[4,4]+2*1*vcov (m226e)[1,4]))
  , c (sum.m226f$coef[c (1:2,4),2], rep (NA, 4), sum.m226f$coef[c (3,5),2], rep (NA, 2), sum.m226f$coef[6:8,2]
       , sqrt (vcov (m226f)[1,1])
       , sqrt (vcov (m226f)[1,1]+1^2*vcov (m226f)[5,5]+2*1*vcov (m226f)[1,5])
       , NA
       , sqrt (vcov (m226f)[1,1]+1^2*vcov (m226f)[4,4]+2*1*vcov (m226f)[1,4]))
  , rep (NA, 18)
  , c (sum.m216g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m216g)[1,1])
       , sqrt (vcov (m216g)[1,1]+1^2*vcov (m216g)[4,4]+2*1*vcov (m216g)[1,4])
       , sqrt (vcov (m216g)[1,1]+1^2*vcov (m216g)[3,3]+2*1*vcov (m216g)[1,3])
       , sqrt (vcov (m216g)[1,1]+1^2*vcov (m216g)[3,3]+1^2*vcov (m216g)[4,4]+1^2*1^2*vcov (m216g)[5,5]+2*1*vcov (m216g)[1,3]+2*1*vcov (m216g)[1,4]+2*1*1*vcov (m216g)[1,5]+2*1*1*vcov (m216g)[3,4]+2*1*1^2*vcov (m216g)[3,5]+2*1*1^2*vcov (m216g)[4,5]))
  , c (sum.m226g$coef[c (1:2,4),2], rep (NA, 4), sum.m226g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m226g)[1,1])
       , sqrt (vcov (m226g)[1,1]+1^2*vcov (m226g)[5,5]+2*1*vcov (m226g)[1,5])
       , NA
       , sqrt (vcov (m226g)[1,1]+1^2*vcov (m226g)[4,4]+2*1*vcov (m226g)[1,4]))
  , rep (NA, 18)
  , c (sum.m216i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m216i)[1,1])
       , sqrt (vcov (m216i)[1,1]+1^2*vcov (m216i)[4,4]+2*1*vcov (m216i)[1,4])
       , sqrt (vcov (m216i)[1,1]+1^2*vcov (m216i)[3,3]+2*1*vcov (m216i)[1,3])
       , sqrt (vcov (m216i)[1,1]+1^2*vcov (m216i)[3,3]+1^2*vcov (m216i)[4,4]+1^2*1^2*vcov (m216i)[5,5]+2*1*vcov (m216i)[1,3]+2*1*vcov (m216i)[1,4]+2*1*1*vcov (m216i)[1,5]+2*1*1*vcov (m216i)[3,4]+2*1*1^2*vcov (m216i)[3,5]+2*1*1^2*vcov (m216i)[4,5]))
  , c (sum.m226i$coef[c (1:2,4),2], rep (NA, 4), sum.m226i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m226i)[1,1])
       , sqrt (vcov (m226i)[1,1]+1^2*vcov (m226i)[5,5]+2*1*vcov (m226i)[1,5])
       , NA
       , sqrt (vcov (m226i)[1,1]+1^2*vcov (m226i)[4,4]+2*1*vcov (m226i)[1,4]))))

odd <- seq (1, nrow (coefOutcome03a)*2, by=2); even <- seq (2, nrow (coefOutcome03a)*2, by=2)
(coefOutcome03tab <- data.frame (rbind (coefOutcome03a, seOutcome03a))) ## warnings reported. Don't worry
rownames (coefOutcome03tab) <- c (odd, even)
coefOutcome03tab <- coefOutcome03tab[order (as.numeric (rownames (coefOutcome03tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m206a$N, length (unique (sum.m206a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m206a$fe$year.f)))
  , c (sum.m216a$N, length (unique (sum.m216a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m216a$fe$year.f)))
  , c (sum.m216c$N, length (unique (sum.m216c$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m216c$fe$year.f)))
  , c (sum.m216e$N, length (unique (sum.m216e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m216e$fe$year.f)))
  , c (sum.m216f$N, length (unique (sum.m216f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m216f$fe$year.f)))
  , c (sum.m226a$N, length (unique (sum.m226a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m226a$fe$year.f)))
  , c (sum.m226e$N, length (unique (sum.m226e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m226e$fe$year.f)))
  , c (sum.m226f$N, length (unique (sum.m226f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m226f$fe$year.f)))
  , c (sum.m216g$N, length (unique (sum.m216g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m216g$fe$year.f)))
  , c (sum.m226g$N, length (unique (sum.m226g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m226g$fe$year.f)))
  , c (sum.m216i$N, length (unique (sum.m216i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m216i$fe$year.f)))
  , c (sum.m226i$N, length (unique (sum.m226i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m226i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (end (voluntary)_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefOutcome03tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Alternative Outcomes (3): Voluntary end"
               , label="T:rOutcomeVoluntary")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (3.3.2) Figure A4

# (3.3.2.1) Marginal effect of growth (t-1) on Pr (voluntary end t):

# creating the dataset for the plots
dPlotOutcome03g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotOutcome03g) <- "dataset"
dPlotOutcome03g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotOutcome03g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotOutcome03g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotOutcome03g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotOutcome03g$estimate <- c (coefOutcome03tab[c (29, 33, 31, 35),5], coefOutcome03tab[c (29, 33, 31, 35),9]
                               , coefOutcome03tab[c (29, 33, 31, 35),6], coefOutcome03tab[c (29, 33, 31, 35),10]
                               , coefOutcome03tab[c (29, 33, 31, 35),12], coefOutcome03tab[c (29, 33, 31, 35),13]
                               , coefOutcome03tab[c (29, 33, 31, 35),15], coefOutcome03tab[c (29, 33, 31, 35),16])
dPlotOutcome03g$se <- c (coefOutcome03tab[c (29, 33, 31, 35)+1,5], coefOutcome03tab[c (29, 33, 31, 35)+1,9]
                         , coefOutcome03tab[c (29, 33, 31, 35)+1,6], coefOutcome03tab[c (29, 33, 31, 35)+1,10]
                         , coefOutcome03tab[c (29, 33, 31, 35)+1,12], coefOutcome03tab[c (29, 33, 31, 35)+1,13]
                         , coefOutcome03tab[c (29, 33, 31, 35)+1,15], coefOutcome03tab[c (29, 33, 31, 35)+1,16])
dPlotOutcome03g$ciLow <- with (dPlotOutcome03g, estimate + se*qt (0.025, df=n))
dPlotOutcome03g$ciHigh <- with (dPlotOutcome03g, estimate + se*qt (0.975, df=n))
dPlotOutcome03g <- dPlotOutcome03g[!is.na (dPlotOutcome03g$estimate),]
dPlotOutcome03g$effect <- factor (dPlotOutcome03g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (3.3.2.2) Marginal effect of election (t) on Pr (voluntary end t):
dPlotOutcome03el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotOutcome03el) <- "dataset"
dPlotOutcome03el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotOutcome03el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotOutcome03el$growth <- rep (seq (min (maddMain$madddGDPHead_lag), max (maddMain$madddGDPHead_lag), length.out=m), 3)
dPlotOutcome03el$estimate <- with (dPlotOutcome03el, ifelse (
  elType=="actual elections\n(closed)", sum.m216e$coef[2,1]+sum.m216e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m216e$coef[2,1]+sum.m216e$coef[7,1]+(sum.m216e$coef[3,1]+sum.m216e$coef[5,1])*growth, sum.m226e$coef[2,1]+sum.m226e$coef[4,1]*growth)))
dPlotOutcome03el$se <- with (dPlotOutcome03el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m216e)[2,2] + (growth^2)*vcov (m216e)[3,3] + (2*growth)*vcov (m216e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m216e)[2,2] + (growth^2)*vcov (m216e)[3,3] + (1^2)*vcov (m216e)[7,7] + (growth^2)*(1^2)*vcov (m216e)[5,5] + (2*growth)*vcov (m216e)[2,3] + (2*1)*vcov (m216e)[2,7] + (2*growth*1)*vcov (m216e)[2,5] + (2*growth*1)*vcov (m216e)[3,7] + (2*1*growth^2)*vcov (m216e)[3,5] + (2*growth*1^2)*vcov (m216e)[7,5]), sqrt (vcov (m226e)[2,2] + (growth^2)*vcov (m226e)[4,4] + (2*growth)*vcov (m226e)[2,4]))))
dPlotOutcome03el$ciLow <- with (dPlotOutcome03el, estimate + se*qt (0.025, df=n))
dPlotOutcome03el$ciHigh <- with (dPlotOutcome03el, estimate + se*qt (0.975, df=n))
dPlotOutcome03el <- dPlotOutcome03el[abs (dPlotOutcome03el$growth) <= h.lim,]

# (3.3.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectOutcomeVoluntary01 <- ggplot (dPlotOutcome03g[dPlotOutcome03g$elType=="competitive\n& executive",]
                                      , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[end (voluntary) (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectOutcomeVoluntary02 <- ggplot (dPlotOutcome03g[dPlotOutcome03g$controls=="no controls",]
                                      , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[end (voluntary) (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthOutcomeVoluntary <- ggplot (maddMain[abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectOutcomeVoluntary03 <- ggplot (dPlotOutcome03el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthOutcomeVoluntary), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[end (voluntary) (t)]"))

# (3.3.2.4) Exporting the plots
png ("Figures/fig_rOutcomeVoluntary01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeVoluntary01
dev.off ()
png ("Figures/fig_rOutcomeVoluntary02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeVoluntary02
dev.off ()
png ("Figures/fig_rOutcomeVoluntary03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectOutcomeVoluntary03
dev.off ()


## (3.4) Table A11
(coefOutcome09a <- cbind (
  c (sum.m200a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m210a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m210c$coef[1:3,1], rep (NA, 6+5), sum.m210c$coef[1,1], sum.m210c$coef[1,1], sum.m210c$coef[1,1]+sum.m210c$coef[3,1], sum.m210c$coef[1,1]+sum.m210c$coef[3,1])
  , c (sum.m210e$coef[1:7,1], rep (NA, 2+5), sum.m210e$coef[1,1], sum.m210e$coef[1,1]+sum.m210e$coef[4,1], sum.m210e$coef[1,1]+sum.m210e$coef[3,1], sum.m210e$coef[1,1]+sum.m210e$coef[3,1]+sum.m210e$coef[4,1]+sum.m210e$coef[5,1])
  , c (sum.m210f$coef[1:7,1], rep (NA, 2+2), sum.m210f$coef[8:10,1], sum.m210f$coef[1,1], sum.m210f$coef[1,1]+sum.m210f$coef[4,1], sum.m210f$coef[1,1]+sum.m210f$coef[3,1], sum.m210f$coef[1,1]+sum.m210f$coef[3,1]+sum.m210f$coef[4,1]+sum.m210f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m220a$coef[1,1], rep (NA, 5), sum.m220a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m220e$coef[c (1:2,4),1], rep (NA, 4), sum.m220e$coef[c (3,5),1], rep (NA, 5), sum.m220e$coef[1,1], sum.m220e$coef[1,1]+sum.m220e$coef[5,1], NA, sum.m220e$coef[1,1]+sum.m220e$coef[4,1])
  , c (sum.m220f$coef[c (1:2,4),1], rep (NA, 4), sum.m220f$coef[c (3,5),1], rep (NA, 2), sum.m220f$coef[6:8,1], sum.m220f$coef[1,1], sum.m220f$coef[1,1]+sum.m220f$coef[5,1], NA, sum.m220f$coef[1,1]+sum.m220f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m210g$coef[1:7,1], rep (NA, 2+5), sum.m210g$coef[1,1], sum.m210g$coef[1,1]+sum.m210g$coef[4,1], sum.m210g$coef[1,1]+sum.m210g$coef[3,1], sum.m210g$coef[1,1]+sum.m210g$coef[3,1]+sum.m210g$coef[4,1]+sum.m210g$coef[5,1])
  , c (sum.m220g$coef[c (1:2,4),1], rep (NA, 4), sum.m220g$coef[c (3,5),1], rep (NA, 5), sum.m220g$coef[1,1], sum.m220g$coef[1,1]+sum.m220g$coef[5,1], NA, sum.m220g$coef[1,1]+sum.m220g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m210i$coef[1:7,1], rep (NA, 2+5), sum.m210i$coef[1,1], sum.m210i$coef[1,1]+sum.m210i$coef[4,1], sum.m210i$coef[1,1]+sum.m210i$coef[3,1], sum.m210i$coef[1,1]+sum.m210i$coef[3,1]+sum.m210i$coef[4,1]+sum.m210i$coef[5,1])
  , c (sum.m220i$coef[c (1:2,4),1], rep (NA, 4), sum.m220i$coef[c (3,5:7),1], rep (NA, 3), sum.m220i$coef[1,1], sum.m220i$coef[1,1]+sum.m220i$coef[5,1], NA, sum.m220i$coef[1,1]+sum.m220i$coef[4,1])))
(seOutcome09a <- cbind (
  c (sum.m200a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m210a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m210c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m210c)[1,1])
       , sqrt (vcov (m210c)[1,1])
       , sqrt (vcov (m210c)[1,1]+1^2*vcov (m210c)[3,3]+2*1*vcov (m210c)[1,3])
       , sqrt (vcov (m210c)[1,1]+1^2*vcov (m210c)[3,3]+2*1*vcov (m210c)[1,3]))
  , c (sum.m210e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m210e)[1,1])
       , sqrt (vcov (m210e)[1,1]+1^2*vcov (m210e)[4,4]+2*1*vcov (m210e)[1,4])
       , sqrt (vcov (m210e)[1,1]+1^2*vcov (m210e)[3,3]+2*1*vcov (m210e)[1,3])
       , sqrt (vcov (m210e)[1,1]+1^2*vcov (m210e)[3,3]+1^2*vcov (m210e)[4,4]+1^2*1^2*vcov (m210e)[5,5]+2*1*vcov (m210e)[1,3]+2*1*vcov (m210e)[1,4]+2*1*1*vcov (m210e)[1,5]+2*1*1*vcov (m210e)[3,4]+2*1*1^2*vcov (m210e)[3,5]+2*1*1^2*vcov (m210e)[4,5]))
  , c (sum.m210f$coef[1:7,2], rep (NA, 2+2), sum.m210f$coef[8:10,2]
       , sqrt (vcov (m210f)[1,1])
       , sqrt (vcov (m210f)[1,1]+1^2*vcov (m210f)[4,4]+2*1*vcov (m210f)[1,4])
       , sqrt (vcov (m210f)[1,1]+1^2*vcov (m210f)[3,3]+2*1*vcov (m210f)[1,3])
       , sqrt (vcov (m210f)[1,1]+1^2*vcov (m210f)[3,3]+1^2*vcov (m210f)[4,4]+1^2*1^2*vcov (m210f)[5,5]+2*1*vcov (m210f)[1,3]+2*1*vcov (m210f)[1,4]+2*1*1*vcov (m210f)[1,5]+2*1*1*vcov (m210f)[3,4]+2*1*1^2*vcov (m210f)[3,5]+2*1*1^2*vcov (m210f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m220a$coef[1,2], rep (NA, 5), sum.m220a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m220e$coef[c (1:2,4),2], rep (NA, 4), sum.m220e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m220e)[1,1])
       , sqrt (vcov (m220e)[1,1]+1^2*vcov (m220e)[5,5]+2*1*vcov (m220e)[1,5])
       , NA
       , sqrt (vcov (m220e)[1,1]+1^2*vcov (m220e)[4,4]+2*1*vcov (m220e)[1,4]))
  , c (sum.m220f$coef[c (1:2,4),2], rep (NA, 4), sum.m220f$coef[c (3,5),2], rep (NA, 2), sum.m220f$coef[6:8,2]
       , sqrt (vcov (m220f)[1,1])
       , sqrt (vcov (m220f)[1,1]+1^2*vcov (m220f)[5,5]+2*1*vcov (m220f)[1,5])
       , NA
       , sqrt (vcov (m220f)[1,1]+1^2*vcov (m220f)[4,4]+2*1*vcov (m220f)[1,4]))
  , rep (NA, 18)
  , c (sum.m210g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m210g)[1,1])
       , sqrt (vcov (m210g)[1,1]+1^2*vcov (m210g)[4,4]+2*1*vcov (m210g)[1,4])
       , sqrt (vcov (m210g)[1,1]+1^2*vcov (m210g)[3,3]+2*1*vcov (m210g)[1,3])
       , sqrt (vcov (m210g)[1,1]+1^2*vcov (m210g)[3,3]+1^2*vcov (m210g)[4,4]+1^2*1^2*vcov (m210g)[5,5]+2*1*vcov (m210g)[1,3]+2*1*vcov (m210g)[1,4]+2*1*1*vcov (m210g)[1,5]+2*1*1*vcov (m210g)[3,4]+2*1*1^2*vcov (m210g)[3,5]+2*1*1^2*vcov (m210g)[4,5]))
  , c (sum.m220g$coef[c (1:2,4),2], rep (NA, 4), sum.m220g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m220g)[1,1])
       , sqrt (vcov (m220g)[1,1]+1^2*vcov (m220g)[5,5]+2*1*vcov (m220g)[1,5])
       , NA
       , sqrt (vcov (m220g)[1,1]+1^2*vcov (m220g)[4,4]+2*1*vcov (m220g)[1,4]))
  , rep (NA, 18)
  , c (sum.m210i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m210i)[1,1])
       , sqrt (vcov (m210i)[1,1]+1^2*vcov (m210i)[4,4]+2*1*vcov (m210i)[1,4])
       , sqrt (vcov (m210i)[1,1]+1^2*vcov (m210i)[3,3]+2*1*vcov (m210i)[1,3])
       , sqrt (vcov (m210i)[1,1]+1^2*vcov (m210i)[3,3]+1^2*vcov (m210i)[4,4]+1^2*1^2*vcov (m210i)[5,5]+2*1*vcov (m210i)[1,3]+2*1*vcov (m210i)[1,4]+2*1*1*vcov (m210i)[1,5]+2*1*1*vcov (m210i)[3,4]+2*1*1^2*vcov (m210i)[3,5]+2*1*1^2*vcov (m210i)[4,5]))
  , c (sum.m220i$coef[c (1:2,4),2], rep (NA, 4), sum.m220i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m220i)[1,1])
       , sqrt (vcov (m220i)[1,1]+1^2*vcov (m220i)[5,5]+2*1*vcov (m220i)[1,5])
       , NA
       , sqrt (vcov (m220i)[1,1]+1^2*vcov (m220i)[4,4]+2*1*vcov (m220i)[1,4]))))

odd <- seq (1, nrow (coefOutcome09a)*2, by=2); even <- seq (2, nrow (coefOutcome09a)*2, by=2)
(coefOutcome09tab <- data.frame (rbind (coefOutcome09a, seOutcome09a))) ## warnings reported. Don't worry
rownames (coefOutcome09tab) <- c (odd, even)
coefOutcome09tab <- coefOutcome09tab[order (as.numeric (rownames (coefOutcome09tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m200a$N, length (unique (sum.m200a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m200a$fe$year.f)))
  , c (sum.m210a$N, length (unique (sum.m210a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m210a$fe$year.f)))
  , c (sum.m210c$N, length (unique (sum.m210c$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m210c$fe$year.f)))
  , c (sum.m210e$N, length (unique (sum.m210e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m210e$fe$year.f)))
  , c (sum.m210f$N, length (unique (sum.m210f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m210f$fe$year.f)))
  , c (sum.m220a$N, length (unique (sum.m220a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m220a$fe$year.f)))
  , c (sum.m220e$N, length (unique (sum.m220e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m220e$fe$year.f)))
  , c (sum.m220f$N, length (unique (sum.m220f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m220f$fe$year.f)))
  , c (sum.m210g$N, length (unique (sum.m210g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m210g$fe$year.f)))
  , c (sum.m220g$N, length (unique (sum.m220g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m220g$fe$year.f)))
  , c (sum.m210i$N, length (unique (sum.m210i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m210i$fe$year.f)))
  , c (sum.m220i$N, length (unique (sum.m220i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m220i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (protest{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefOutcome09tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Alternative Outcomes (4): Protest(s)"
               , label="T:rOutcomeProtest")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (3.4.2) Figure A5

# (3.4.2.1) Marginal effect of growth (t-1) on Pr (democracy t+1):

# creating the dataset for the plots
dPlotOutcome09g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotOutcome09g) <- "dataset"
dPlotOutcome09g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotOutcome09g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotOutcome09g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotOutcome09g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotOutcome09g$estimate <- c (coefOutcome09tab[c (29, 33, 31, 35),5], coefOutcome09tab[c (29, 33, 31, 35),9]
                               , coefOutcome09tab[c (29, 33, 31, 35),6], coefOutcome09tab[c (29, 33, 31, 35),10]
                               , coefOutcome09tab[c (29, 33, 31, 35),12], coefOutcome09tab[c (29, 33, 31, 35),13]
                               , coefOutcome09tab[c (29, 33, 31, 35),15], coefOutcome09tab[c (29, 33, 31, 35),16])
dPlotOutcome09g$se <- c (coefOutcome09tab[c (29, 33, 31, 35)+1,5], coefOutcome09tab[c (29, 33, 31, 35)+1,9]
                         , coefOutcome09tab[c (29, 33, 31, 35)+1,6], coefOutcome09tab[c (29, 33, 31, 35)+1,10]
                         , coefOutcome09tab[c (29, 33, 31, 35)+1,12], coefOutcome09tab[c (29, 33, 31, 35)+1,13]
                         , coefOutcome09tab[c (29, 33, 31, 35)+1,15], coefOutcome09tab[c (29, 33, 31, 35)+1,16])
dPlotOutcome09g$ciLow <- with (dPlotOutcome09g, estimate + se*qt (0.025, df=n))
dPlotOutcome09g$ciHigh <- with (dPlotOutcome09g, estimate + se*qt (0.975, df=n))
dPlotOutcome09g <- dPlotOutcome09g[!is.na (dPlotOutcome09g$estimate),]
dPlotOutcome09g$effect <- factor (dPlotOutcome09g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (3.4.2.2) Marginal effect of election (t) on Pr (protest t):
dPlotOutcome09el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotOutcome09el) <- "dataset"
dPlotOutcome09el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotOutcome09el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotOutcome09el$growth <- rep (seq (min (maddMain$madddGDPHead_lag), max (maddMain$madddGDPHead_lag), length.out=m), 3)
dPlotOutcome09el$estimate <- with (dPlotOutcome09el, ifelse (
  elType=="actual elections\n(closed)", sum.m210e$coef[2,1]+sum.m210e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m210e$coef[2,1]+sum.m210e$coef[7,1]+(sum.m210e$coef[3,1]+sum.m210e$coef[5,1])*growth, sum.m220e$coef[2,1]+sum.m220e$coef[4,1]*growth)))
dPlotOutcome09el$se <- with (dPlotOutcome09el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m210e)[2,2] + (growth^2)*vcov (m210e)[3,3] + (2*growth)*vcov (m210e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m210e)[2,2] + (growth^2)*vcov (m210e)[3,3] + (1^2)*vcov (m210e)[7,7] + (growth^2)*(1^2)*vcov (m210e)[5,5] + (2*growth)*vcov (m210e)[2,3] + (2*1)*vcov (m210e)[2,7] + (2*growth*1)*vcov (m210e)[2,5] + (2*growth*1)*vcov (m210e)[3,7] + (2*1*growth^2)*vcov (m210e)[3,5] + (2*growth*1^2)*vcov (m210e)[7,5]), sqrt (vcov (m220e)[2,2] + (growth^2)*vcov (m220e)[4,4] + (2*growth)*vcov (m220e)[2,4]))))
dPlotOutcome09el$ciLow <- with (dPlotOutcome09el, estimate + se*qt (0.025, df=n))
dPlotOutcome09el$ciHigh <- with (dPlotOutcome09el, estimate + se*qt (0.975, df=n))
dPlotOutcome09el <- dPlotOutcome09el[abs (dPlotOutcome09el$growth) <= h.lim,]

# (3.4.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectOutcomeProtest01 <- ggplot (dPlotOutcome09g[dPlotOutcome09g$elType=="competitive\n& executive",]
                                    , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[protest (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectOutcomeProtest02 <- ggplot (dPlotOutcome09g[dPlotOutcome09g$controls=="no controls",]
                                    , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[protest (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthOutcomeProtest <- ggplot (maddMain[!is.na (maddMain$protestD) & abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectOutcomeProtest03 <- ggplot (dPlotOutcome09el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthOutcomeProtest), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[protest (t)]"))

# (3.4.2.4) Exporting the plots
png ("Figures/fig_rOutcomeProtest01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeProtest01
dev.off ()
png ("Figures/fig_rOutcomeProtest02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeProtest02
dev.off ()
png ("Figures/fig_rOutcomeProtest03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectOutcomeProtest03
dev.off ()


## (3.5) Table A12
(coefOutcome10a <- cbind (
  c (sum.m201a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m211a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m211c$coef[1:3,1], rep (NA, 6+5), sum.m211c$coef[1,1], sum.m211c$coef[1,1], sum.m211c$coef[1,1]+sum.m211c$coef[3,1], sum.m211c$coef[1,1]+sum.m211c$coef[3,1])
  , c (sum.m211e$coef[1:7,1], rep (NA, 2+5), sum.m211e$coef[1,1], sum.m211e$coef[1,1]+sum.m211e$coef[4,1], sum.m211e$coef[1,1]+sum.m211e$coef[3,1], sum.m211e$coef[1,1]+sum.m211e$coef[3,1]+sum.m211e$coef[4,1]+sum.m211e$coef[5,1])
  , c (sum.m211f$coef[1:7,1], rep (NA, 2+2), sum.m211f$coef[8:10,1], sum.m211f$coef[1,1], sum.m211f$coef[1,1]+sum.m211f$coef[4,1], sum.m211f$coef[1,1]+sum.m211f$coef[3,1], sum.m211f$coef[1,1]+sum.m211f$coef[3,1]+sum.m211f$coef[4,1]+sum.m211f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m221a$coef[1,1], rep (NA, 5), sum.m221a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m221e$coef[c (1:2,4),1], rep (NA, 4), sum.m221e$coef[c (3,5),1], rep (NA, 5), sum.m221e$coef[1,1], sum.m221e$coef[1,1]+sum.m221e$coef[5,1], NA, sum.m221e$coef[1,1]+sum.m221e$coef[4,1])
  , c (sum.m221f$coef[c (1:2,4),1], rep (NA, 4), sum.m221f$coef[c (3,5),1], rep (NA, 2), sum.m221f$coef[6:8,1], sum.m221f$coef[1,1], sum.m221f$coef[1,1]+sum.m221f$coef[5,1], NA, sum.m221f$coef[1,1]+sum.m221f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m211g$coef[1:7,1], rep (NA, 2+5), sum.m211g$coef[1,1], sum.m211g$coef[1,1]+sum.m211g$coef[4,1], sum.m211g$coef[1,1]+sum.m211g$coef[3,1], sum.m211g$coef[1,1]+sum.m211g$coef[3,1]+sum.m211g$coef[4,1]+sum.m211g$coef[5,1])
  , c (sum.m221g$coef[c (1:2,4),1], rep (NA, 4), sum.m221g$coef[c (3,5),1], rep (NA, 5), sum.m221g$coef[1,1], sum.m221g$coef[1,1]+sum.m221g$coef[5,1], NA, sum.m221g$coef[1,1]+sum.m221g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m211i$coef[1:7,1], rep (NA, 2+5), sum.m211i$coef[1,1], sum.m211i$coef[1,1]+sum.m211i$coef[4,1], sum.m211i$coef[1,1]+sum.m211i$coef[3,1], sum.m211i$coef[1,1]+sum.m211i$coef[3,1]+sum.m211i$coef[4,1]+sum.m211i$coef[5,1])
  , c (sum.m221i$coef[c (1:2,4),1], rep (NA, 4), sum.m221i$coef[c (3,5:7),1], rep (NA, 3), sum.m221i$coef[1,1], sum.m221i$coef[1,1]+sum.m221i$coef[5,1], NA, sum.m221i$coef[1,1]+sum.m221i$coef[4,1])))
(seOutcome10a <- cbind (
  c (sum.m201a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m211a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m211c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m211c)[1,1])
       , sqrt (vcov (m211c)[1,1])
       , sqrt (vcov (m211c)[1,1]+1^2*vcov (m211c)[3,3]+2*1*vcov (m211c)[1,3])
       , sqrt (vcov (m211c)[1,1]+1^2*vcov (m211c)[3,3]+2*1*vcov (m211c)[1,3]))
  , c (sum.m211e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m211e)[1,1])
       , sqrt (vcov (m211e)[1,1]+1^2*vcov (m211e)[4,4]+2*1*vcov (m211e)[1,4])
       , sqrt (vcov (m211e)[1,1]+1^2*vcov (m211e)[3,3]+2*1*vcov (m211e)[1,3])
       , sqrt (vcov (m211e)[1,1]+1^2*vcov (m211e)[3,3]+1^2*vcov (m211e)[4,4]+1^2*1^2*vcov (m211e)[5,5]+2*1*vcov (m211e)[1,3]+2*1*vcov (m211e)[1,4]+2*1*1*vcov (m211e)[1,5]+2*1*1*vcov (m211e)[3,4]+2*1*1^2*vcov (m211e)[3,5]+2*1*1^2*vcov (m211e)[4,5]))
  , c (sum.m211f$coef[1:7,2], rep (NA, 2+2), sum.m211f$coef[8:10,2]
       , sqrt (vcov (m211f)[1,1])
       , sqrt (vcov (m211f)[1,1]+1^2*vcov (m211f)[4,4]+2*1*vcov (m211f)[1,4])
       , sqrt (vcov (m211f)[1,1]+1^2*vcov (m211f)[3,3]+2*1*vcov (m211f)[1,3])
       , sqrt (vcov (m211f)[1,1]+1^2*vcov (m211f)[3,3]+1^2*vcov (m211f)[4,4]+1^2*1^2*vcov (m211f)[5,5]+2*1*vcov (m211f)[1,3]+2*1*vcov (m211f)[1,4]+2*1*1*vcov (m211f)[1,5]+2*1*1*vcov (m211f)[3,4]+2*1*1^2*vcov (m211f)[3,5]+2*1*1^2*vcov (m211f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m221a$coef[1,2], rep (NA, 5), sum.m221a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m221e$coef[c (1:2,4),2], rep (NA, 4), sum.m221e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m221e)[1,1])
       , sqrt (vcov (m221e)[1,1]+1^2*vcov (m221e)[5,5]+2*1*vcov (m221e)[1,5])
       , NA
       , sqrt (vcov (m221e)[1,1]+1^2*vcov (m221e)[4,4]+2*1*vcov (m221e)[1,4]))
  , c (sum.m221f$coef[c (1:2,4),2], rep (NA, 4), sum.m221f$coef[c (3,5),2], rep (NA, 2), sum.m221f$coef[6:8,2]
       , sqrt (vcov (m221f)[1,1])
       , sqrt (vcov (m221f)[1,1]+1^2*vcov (m221f)[5,5]+2*1*vcov (m221f)[1,5])
       , NA
       , sqrt (vcov (m221f)[1,1]+1^2*vcov (m221f)[4,4]+2*1*vcov (m221f)[1,4]))
  , rep (NA, 18)
  , c (sum.m211g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m211g)[1,1])
       , sqrt (vcov (m211g)[1,1]+1^2*vcov (m211g)[4,4]+2*1*vcov (m211g)[1,4])
       , sqrt (vcov (m211g)[1,1]+1^2*vcov (m211g)[3,3]+2*1*vcov (m211g)[1,3])
       , sqrt (vcov (m211g)[1,1]+1^2*vcov (m211g)[3,3]+1^2*vcov (m211g)[4,4]+1^2*1^2*vcov (m211g)[5,5]+2*1*vcov (m211g)[1,3]+2*1*vcov (m211g)[1,4]+2*1*1*vcov (m211g)[1,5]+2*1*1*vcov (m211g)[3,4]+2*1*1^2*vcov (m211g)[3,5]+2*1*1^2*vcov (m211g)[4,5]))
  , c (sum.m221g$coef[c (1:2,4),2], rep (NA, 4), sum.m221g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m221g)[1,1])
       , sqrt (vcov (m221g)[1,1]+1^2*vcov (m221g)[5,5]+2*1*vcov (m221g)[1,5])
       , NA
       , sqrt (vcov (m221g)[1,1]+1^2*vcov (m221g)[4,4]+2*1*vcov (m221g)[1,4]))
  , rep (NA, 18)
  , c (sum.m211i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m211i)[1,1])
       , sqrt (vcov (m211i)[1,1]+1^2*vcov (m211i)[4,4]+2*1*vcov (m211i)[1,4])
       , sqrt (vcov (m211i)[1,1]+1^2*vcov (m211i)[3,3]+2*1*vcov (m211i)[1,3])
       , sqrt (vcov (m211i)[1,1]+1^2*vcov (m211i)[3,3]+1^2*vcov (m211i)[4,4]+1^2*1^2*vcov (m211i)[5,5]+2*1*vcov (m211i)[1,3]+2*1*vcov (m211i)[1,4]+2*1*1*vcov (m211i)[1,5]+2*1*1*vcov (m211i)[3,4]+2*1*1^2*vcov (m211i)[3,5]+2*1*1^2*vcov (m211i)[4,5]))
  , c (sum.m221i$coef[c (1:2,4),2], rep (NA, 4), sum.m221i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m221i)[1,1])
       , sqrt (vcov (m221i)[1,1]+1^2*vcov (m221i)[5,5]+2*1*vcov (m221i)[1,5])
       , NA
       , sqrt (vcov (m221i)[1,1]+1^2*vcov (m221i)[4,4]+2*1*vcov (m221i)[1,4]))))

odd <- seq (1, nrow (coefOutcome10a)*2, by=2); even <- seq (2, nrow (coefOutcome10a)*2, by=2)
(coefOutcome10tab <- data.frame (rbind (coefOutcome10a, seOutcome10a))) ## warnings reported. Don't worry
rownames (coefOutcome10tab) <- c (odd, even)
coefOutcome10tab <- coefOutcome10tab[order (as.numeric (rownames (coefOutcome10tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m201a$N, length (unique (sum.m201a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m201a$fe$year.f)))
  , c (sum.m211a$N, length (unique (sum.m211a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m211a$fe$year.f)))
  , c (sum.m211c$N, length (unique (sum.m211c$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m211c$fe$year.f)))
  , c (sum.m211e$N, length (unique (sum.m211e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m211e$fe$year.f)))
  , c (sum.m211f$N, length (unique (sum.m211f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2010_lag),]$country)), length (unique (sum.m211f$fe$year.f)))
  , c (sum.m221a$N, length (unique (sum.m221a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m221a$fe$year.f)))
  , c (sum.m221e$N, length (unique (sum.m221e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m221e$fe$year.f)))
  , c (sum.m221f$N, length (unique (sum.m221f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2010_lag),]$country)), length (unique (sum.m221f$fe$year.f)))
  , c (sum.m211g$N, length (unique (sum.m211g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m211g$fe$year.f)))
  , c (sum.m221g$N, length (unique (sum.m221g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m221g$fe$year.f)))
  , c (sum.m211i$N, length (unique (sum.m211i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m211i$fe$year.f)))
  , c (sum.m221i$N, length (unique (sum.m221i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m221i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (violent protest{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefOutcome10tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Alternative Outcomes (5): Violent protest(s)"
               , label="T:rOutcomeProtestViolent")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (3.5.2) Figure A6

# (3.5.2.1) Marginal effect of growth (t-1) on Pr (violent protest t):

# creating the dataset for the plots
dPlotOutcome10g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotOutcome10g) <- "dataset"
dPlotOutcome10g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotOutcome10g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotOutcome10g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotOutcome10g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotOutcome10g$estimate <- c (coefOutcome10tab[c (29, 33, 31, 35),5], coefOutcome10tab[c (29, 33, 31, 35),9]
                               , coefOutcome10tab[c (29, 33, 31, 35),6], coefOutcome10tab[c (29, 33, 31, 35),10]
                               , coefOutcome10tab[c (29, 33, 31, 35),12], coefOutcome10tab[c (29, 33, 31, 35),13]
                               , coefOutcome10tab[c (29, 33, 31, 35),15], coefOutcome10tab[c (29, 33, 31, 35),16])
dPlotOutcome10g$se <- c (coefOutcome10tab[c (29, 33, 31, 35)+1,5], coefOutcome10tab[c (29, 33, 31, 35)+1,9]
                         , coefOutcome10tab[c (29, 33, 31, 35)+1,6], coefOutcome10tab[c (29, 33, 31, 35)+1,10]
                         , coefOutcome10tab[c (29, 33, 31, 35)+1,12], coefOutcome10tab[c (29, 33, 31, 35)+1,13]
                         , coefOutcome10tab[c (29, 33, 31, 35)+1,15], coefOutcome10tab[c (29, 33, 31, 35)+1,16])
dPlotOutcome10g$ciLow <- with (dPlotOutcome10g, estimate + se*qt (0.025, df=n))
dPlotOutcome10g$ciHigh <- with (dPlotOutcome10g, estimate + se*qt (0.975, df=n))
dPlotOutcome10g <- dPlotOutcome10g[!is.na (dPlotOutcome10g$estimate),]
dPlotOutcome10g$effect <- factor (dPlotOutcome10g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (3.5.2.2) Marginal effect of election (t) on Pr (protest t):
dPlotOutcome10el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotOutcome10el) <- "dataset"
dPlotOutcome10el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotOutcome10el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotOutcome10el$growth <- rep (seq (min (maddMain$madddGDPHead_lag), max (maddMain$madddGDPHead_lag), length.out=m), 3)
dPlotOutcome10el$estimate <- with (dPlotOutcome10el, ifelse (
  elType=="actual elections\n(closed)", sum.m211e$coef[2,1]+sum.m211e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m211e$coef[2,1]+sum.m211e$coef[7,1]+(sum.m211e$coef[3,1]+sum.m211e$coef[5,1])*growth, sum.m221e$coef[2,1]+sum.m221e$coef[4,1]*growth)))
dPlotOutcome10el$se <- with (dPlotOutcome10el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m211e)[2,2] + (growth^2)*vcov (m211e)[3,3] + (2*growth)*vcov (m211e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m211e)[2,2] + (growth^2)*vcov (m211e)[3,3] + (1^2)*vcov (m211e)[7,7] + (growth^2)*(1^2)*vcov (m211e)[5,5] + (2*growth)*vcov (m211e)[2,3] + (2*1)*vcov (m211e)[2,7] + (2*growth*1)*vcov (m211e)[2,5] + (2*growth*1)*vcov (m211e)[3,7] + (2*1*growth^2)*vcov (m211e)[3,5] + (2*growth*1^2)*vcov (m211e)[7,5]), sqrt (vcov (m221e)[2,2] + (growth^2)*vcov (m221e)[4,4] + (2*growth)*vcov (m221e)[2,4]))))
dPlotOutcome10el$ciLow <- with (dPlotOutcome10el, estimate + se*qt (0.025, df=n))
dPlotOutcome10el$ciHigh <- with (dPlotOutcome10el, estimate + se*qt (0.975, df=n))
dPlotOutcome10el <- dPlotOutcome10el[abs (dPlotOutcome10el$growth) <= h.lim,]

# (3.5.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectOutcomeProtestViolent01 <- ggplot (dPlotOutcome10g[dPlotOutcome10g$elType=="competitive\n& executive",]
                                           , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[violent protest (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectOutcomeProtestViolent02 <- ggplot (dPlotOutcome10g[dPlotOutcome10g$controls=="no controls",]
                                           , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[violent protest (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthOutcomeProtestViolent <- ggplot (maddMain[!is.na (maddMain$protestViolentD) & abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectOutcomeProtestViolent03 <- ggplot (dPlotOutcome10el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthOutcomeProtestViolent), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[violent protest (t)]"))

# (3.5.2.4) Exporting the plots
png ("Figures/fig_rOutcomeProtestViolent01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeProtestViolent01
dev.off ()
png ("Figures/fig_rOutcomeProtestViolent02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeProtestViolent02
dev.off ()
png ("Figures/fig_rOutcomeProtestViolent03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectOutcomeProtestViolent03
dev.off ()


## (3.6) Table A13
(coefOutcome04a <- cbind (
  c (sum.m207a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m217a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m217c$coef[1:3,1], rep (NA, 6+5), sum.m217c$coef[1,1], sum.m217c$coef[1,1], sum.m217c$coef[1,1]+sum.m217c$coef[3,1], sum.m217c$coef[1,1]+sum.m217c$coef[3,1])
  , c (sum.m217e$coef[1:7,1], rep (NA, 2+5), sum.m217e$coef[1,1], sum.m217e$coef[1,1]+sum.m217e$coef[4,1], sum.m217e$coef[1,1]+sum.m217e$coef[3,1], sum.m217e$coef[1,1]+sum.m217e$coef[3,1]+sum.m217e$coef[4,1]+sum.m217e$coef[5,1])
  , c (sum.m217f$coef[1:7,1], rep (NA, 2+2), sum.m217f$coef[8:10,1], sum.m217f$coef[1,1], sum.m217f$coef[1,1]+sum.m217f$coef[4,1], sum.m217f$coef[1,1]+sum.m217f$coef[3,1], sum.m217f$coef[1,1]+sum.m217f$coef[3,1]+sum.m217f$coef[4,1]+sum.m217f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m227a$coef[1,1], rep (NA, 5), sum.m227a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m227e$coef[c (1:2,4),1], rep (NA, 4), sum.m227e$coef[c (3,5),1], rep (NA, 5), sum.m227e$coef[1,1], sum.m227e$coef[1,1]+sum.m227e$coef[5,1], NA, sum.m227e$coef[1,1]+sum.m227e$coef[4,1])
  , c (sum.m227f$coef[c (1:2,4),1], rep (NA, 4), sum.m227f$coef[c (3,5),1], rep (NA, 2), sum.m227f$coef[6:8,1], sum.m227f$coef[1,1], sum.m227f$coef[1,1]+sum.m227f$coef[5,1], NA, sum.m227f$coef[1,1]+sum.m227f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m217g$coef[1:7,1], rep (NA, 2+5), sum.m217g$coef[1,1], sum.m217g$coef[1,1]+sum.m217g$coef[4,1], sum.m217g$coef[1,1]+sum.m217g$coef[3,1], sum.m217g$coef[1,1]+sum.m217g$coef[3,1]+sum.m217g$coef[4,1]+sum.m217g$coef[5,1])
  , c (sum.m227g$coef[c (1:2,4),1], rep (NA, 4), sum.m227g$coef[c (3,5),1], rep (NA, 5), sum.m227g$coef[1,1], sum.m227g$coef[1,1]+sum.m227g$coef[5,1], NA, sum.m227g$coef[1,1]+sum.m227g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m217i$coef[1:7,1], rep (NA, 2+5), sum.m217i$coef[1,1], sum.m217i$coef[1,1]+sum.m217i$coef[4,1], sum.m217i$coef[1,1]+sum.m217i$coef[3,1], sum.m217i$coef[1,1]+sum.m217i$coef[3,1]+sum.m217i$coef[4,1]+sum.m217i$coef[5,1])
  , c (sum.m227i$coef[c (1:2,4),1], rep (NA, 4), sum.m227i$coef[c (3,5:7),1], rep (NA, 3), sum.m227i$coef[1,1], sum.m227i$coef[1,1]+sum.m227i$coef[5,1], NA, sum.m227i$coef[1,1]+sum.m227i$coef[4,1])))
(seOutcome04a <- cbind (
  c (sum.m207a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m217a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m217c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m217c)[1,1])
       , sqrt (vcov (m217c)[1,1])
       , sqrt (vcov (m217c)[1,1]+1^2*vcov (m217c)[3,3]+2*1*vcov (m217c)[1,3])
       , sqrt (vcov (m217c)[1,1]+1^2*vcov (m217c)[3,3]+2*1*vcov (m217c)[1,3]))
  , c (sum.m217e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m217e)[1,1])
       , sqrt (vcov (m217e)[1,1]+1^2*vcov (m217e)[4,4]+2*1*vcov (m217e)[1,4])
       , sqrt (vcov (m217e)[1,1]+1^2*vcov (m217e)[3,3]+2*1*vcov (m217e)[1,3])
       , sqrt (vcov (m217e)[1,1]+1^2*vcov (m217e)[3,3]+1^2*vcov (m217e)[4,4]+1^2*1^2*vcov (m217e)[5,5]+2*1*vcov (m217e)[1,3]+2*1*vcov (m217e)[1,4]+2*1*1*vcov (m217e)[1,5]+2*1*1*vcov (m217e)[3,4]+2*1*1^2*vcov (m217e)[3,5]+2*1*1^2*vcov (m217e)[4,5]))
  , c (sum.m217f$coef[1:7,2], rep (NA, 2+2), sum.m217f$coef[8:10,2]
       , sqrt (vcov (m217f)[1,1])
       , sqrt (vcov (m217f)[1,1]+1^2*vcov (m217f)[4,4]+2*1*vcov (m217f)[1,4])
       , sqrt (vcov (m217f)[1,1]+1^2*vcov (m217f)[3,3]+2*1*vcov (m217f)[1,3])
       , sqrt (vcov (m217f)[1,1]+1^2*vcov (m217f)[3,3]+1^2*vcov (m217f)[4,4]+1^2*1^2*vcov (m217f)[5,5]+2*1*vcov (m217f)[1,3]+2*1*vcov (m217f)[1,4]+2*1*1*vcov (m217f)[1,5]+2*1*1*vcov (m217f)[3,4]+2*1*1^2*vcov (m217f)[3,5]+2*1*1^2*vcov (m217f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m227a$coef[1,2], rep (NA, 5), sum.m227a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m227e$coef[c (1:2,4),2], rep (NA, 4), sum.m227e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m227e)[1,1])
       , sqrt (vcov (m227e)[1,1]+1^2*vcov (m227e)[5,5]+2*1*vcov (m227e)[1,5])
       , NA
       , sqrt (vcov (m227e)[1,1]+1^2*vcov (m227e)[4,4]+2*1*vcov (m227e)[1,4]))
  , c (sum.m227f$coef[c (1:2,4),2], rep (NA, 4), sum.m227f$coef[c (3,5),2], rep (NA, 2), sum.m227f$coef[6:8,2]
       , sqrt (vcov (m227f)[1,1])
       , sqrt (vcov (m227f)[1,1]+1^2*vcov (m227f)[5,5]+2*1*vcov (m227f)[1,5])
       , NA
       , sqrt (vcov (m227f)[1,1]+1^2*vcov (m227f)[4,4]+2*1*vcov (m227f)[1,4]))
  , rep (NA, 18)
  , c (sum.m217g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m217g)[1,1])
       , sqrt (vcov (m217g)[1,1]+1^2*vcov (m217g)[4,4]+2*1*vcov (m217g)[1,4])
       , sqrt (vcov (m217g)[1,1]+1^2*vcov (m217g)[3,3]+2*1*vcov (m217g)[1,3])
       , sqrt (vcov (m217g)[1,1]+1^2*vcov (m217g)[3,3]+1^2*vcov (m217g)[4,4]+1^2*1^2*vcov (m217g)[5,5]+2*1*vcov (m217g)[1,3]+2*1*vcov (m217g)[1,4]+2*1*1*vcov (m217g)[1,5]+2*1*1*vcov (m217g)[3,4]+2*1*1^2*vcov (m217g)[3,5]+2*1*1^2*vcov (m217g)[4,5]))
  , c (sum.m227g$coef[c (1:2,4),2], rep (NA, 4), sum.m227g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m227g)[1,1])
       , sqrt (vcov (m227g)[1,1]+1^2*vcov (m227g)[5,5]+2*1*vcov (m227g)[1,5])
       , NA
       , sqrt (vcov (m227g)[1,1]+1^2*vcov (m227g)[4,4]+2*1*vcov (m227g)[1,4]))
  , rep (NA, 18)
  , c (sum.m217i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m217i)[1,1])
       , sqrt (vcov (m217i)[1,1]+1^2*vcov (m217i)[4,4]+2*1*vcov (m217i)[1,4])
       , sqrt (vcov (m217i)[1,1]+1^2*vcov (m217i)[3,3]+2*1*vcov (m217i)[1,3])
       , sqrt (vcov (m217i)[1,1]+1^2*vcov (m217i)[3,3]+1^2*vcov (m217i)[4,4]+1^2*1^2*vcov (m217i)[5,5]+2*1*vcov (m217i)[1,3]+2*1*vcov (m217i)[1,4]+2*1*1*vcov (m217i)[1,5]+2*1*1*vcov (m217i)[3,4]+2*1*1^2*vcov (m217i)[3,5]+2*1*1^2*vcov (m217i)[4,5]))
  , c (sum.m227i$coef[c (1:2,4),2], rep (NA, 4), sum.m227i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m227i)[1,1])
       , sqrt (vcov (m227i)[1,1]+1^2*vcov (m227i)[5,5]+2*1*vcov (m227i)[1,5])
       , NA
       , sqrt (vcov (m227i)[1,1]+1^2*vcov (m227i)[4,4]+2*1*vcov (m227i)[1,4]))))

odd <- seq (1, nrow (coefOutcome04a)*2, by=2); even <- seq (2, nrow (coefOutcome04a)*2, by=2)
(coefOutcome04tab <- data.frame (rbind (coefOutcome04a, seOutcome04a))) ## warnings reported. Don't worry
rownames (coefOutcome04tab) <- c (odd, even)
coefOutcome04tab <- coefOutcome04tab[order (as.numeric (rownames (coefOutcome04tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m207a$N, length (unique (sum.m207a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m207a$fe$year.f)))
  , c (sum.m217a$N, length (unique (sum.m217a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m217a$fe$year.f)))
  , c (sum.m217c$N, length (unique (sum.m217c$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m217c$fe$year.f)))
  , c (sum.m217e$N, length (unique (sum.m217e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m217e$fe$year.f)))
  , c (sum.m217f$N, length (unique (sum.m217f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m217f$fe$year.f)))
  , c (sum.m227a$N, length (unique (sum.m227a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m227a$fe$year.f)))
  , c (sum.m227e$N, length (unique (sum.m227e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m227e$fe$year.f)))
  , c (sum.m227f$N, length (unique (sum.m227f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m227f$fe$year.f)))
  , c (sum.m217g$N, length (unique (sum.m217g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m217g$fe$year.f)))
  , c (sum.m227g$N, length (unique (sum.m227g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m227g$fe$year.f)))
  , c (sum.m217i$N, length (unique (sum.m217i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m217i$fe$year.f)))
  , c (sum.m227i$N, length (unique (sum.m227i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m227i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (coup attempt_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefOutcome04tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Alternative Outcomes (6): Coup attempt"
               , label="T:rOutcomeCoup")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (3.6.2) Figure A7

# (3.6.2.1) Marginal effect of growth (t-1) on Pr (coup attempt t):

# creating the dataset for the plots
dPlotOutcome04g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotOutcome04g) <- "dataset"
dPlotOutcome04g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotOutcome04g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotOutcome04g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotOutcome04g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotOutcome04g$estimate <- c (coefOutcome04tab[c (29, 33, 31, 35),5], coefOutcome04tab[c (29, 33, 31, 35),9]
                               , coefOutcome04tab[c (29, 33, 31, 35),6], coefOutcome04tab[c (29, 33, 31, 35),10]
                               , coefOutcome04tab[c (29, 33, 31, 35),12], coefOutcome04tab[c (29, 33, 31, 35),13]
                               , coefOutcome04tab[c (29, 33, 31, 35),15], coefOutcome04tab[c (29, 33, 31, 35),16])
dPlotOutcome04g$se <- c (coefOutcome04tab[c (29, 33, 31, 35)+1,5], coefOutcome04tab[c (29, 33, 31, 35)+1,9]
                         , coefOutcome04tab[c (29, 33, 31, 35)+1,6], coefOutcome04tab[c (29, 33, 31, 35)+1,10]
                         , coefOutcome04tab[c (29, 33, 31, 35)+1,12], coefOutcome04tab[c (29, 33, 31, 35)+1,13]
                         , coefOutcome04tab[c (29, 33, 31, 35)+1,15], coefOutcome04tab[c (29, 33, 31, 35)+1,16])
dPlotOutcome04g$ciLow <- with (dPlotOutcome04g, estimate + se*qt (0.025, df=n))
dPlotOutcome04g$ciHigh <- with (dPlotOutcome04g, estimate + se*qt (0.975, df=n))
dPlotOutcome04g <- dPlotOutcome04g[!is.na (dPlotOutcome04g$estimate),]
dPlotOutcome04g$effect <- factor (dPlotOutcome04g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (3.6.2.2) Marginal effect of election (t) on Pr (coup attempt t):
dPlotOutcome04el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotOutcome04el) <- "dataset"
dPlotOutcome04el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotOutcome04el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotOutcome04el$growth <- rep (seq (min (maddMain$madddGDPHead_lag), max (maddMain$madddGDPHead_lag), length.out=m), 3)
dPlotOutcome04el$estimate <- with (dPlotOutcome04el, ifelse (
  elType=="actual elections\n(closed)", sum.m217e$coef[2,1]+sum.m217e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m217e$coef[2,1]+sum.m217e$coef[7,1]+(sum.m217e$coef[3,1]+sum.m217e$coef[5,1])*growth, sum.m227e$coef[2,1]+sum.m227e$coef[4,1]*growth)))
dPlotOutcome04el$se <- with (dPlotOutcome04el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m217e)[2,2] + (growth^2)*vcov (m217e)[3,3] + (2*growth)*vcov (m217e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m217e)[2,2] + (growth^2)*vcov (m217e)[3,3] + (1^2)*vcov (m217e)[7,7] + (growth^2)*(1^2)*vcov (m217e)[5,5] + (2*growth)*vcov (m217e)[2,3] + (2*1)*vcov (m217e)[2,7] + (2*growth*1)*vcov (m217e)[2,5] + (2*growth*1)*vcov (m217e)[3,7] + (2*1*growth^2)*vcov (m217e)[3,5] + (2*growth*1^2)*vcov (m217e)[7,5]), sqrt (vcov (m227e)[2,2] + (growth^2)*vcov (m227e)[4,4] + (2*growth)*vcov (m227e)[2,4]))))
dPlotOutcome04el$ciLow <- with (dPlotOutcome04el, estimate + se*qt (0.025, df=n))
dPlotOutcome04el$ciHigh <- with (dPlotOutcome04el, estimate + se*qt (0.975, df=n))
dPlotOutcome04el <- dPlotOutcome04el[abs (dPlotOutcome04el$growth) <= h.lim,]

# (3.6.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectOutcomeCoup01 <- ggplot (dPlotOutcome04g[dPlotOutcome04g$elType=="competitive\n& executive",]
                                 , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[coup attempt (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectOutcomeCoup02 <- ggplot (dPlotOutcome04g[dPlotOutcome04g$controls=="no controls",]
                                 , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[coup attempt (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthOutcomeCoup <- ggplot (maddMain[abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectOutcomeCoup03 <- ggplot (dPlotOutcome04el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthOutcomeCoup), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[coup attempt (t)]"))

# (3.6.2.4) Exporting the plots
png ("Figures/fig_rOutcomeCoup01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeCoup01
dev.off ()
png ("Figures/fig_rOutcomeCoup02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeCoup02
dev.off ()
png ("Figures/fig_rOutcomeCoup03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectOutcomeCoup03
dev.off ()


## (3.7) Table A14
(coefOutcome05a <- cbind (
  c (sum.m208a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m218a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m218c$coef[1:3,1], rep (NA, 6+5), sum.m218c$coef[1,1], sum.m218c$coef[1,1], sum.m218c$coef[1,1]+sum.m218c$coef[3,1], sum.m218c$coef[1,1]+sum.m218c$coef[3,1])
  , c (sum.m218e$coef[1:7,1], rep (NA, 2+5), sum.m218e$coef[1,1], sum.m218e$coef[1,1]+sum.m218e$coef[4,1], sum.m218e$coef[1,1]+sum.m218e$coef[3,1], sum.m218e$coef[1,1]+sum.m218e$coef[3,1]+sum.m218e$coef[4,1]+sum.m218e$coef[5,1])
  , c (sum.m218f$coef[1:7,1], rep (NA, 2+2), sum.m218f$coef[8:10,1], sum.m218f$coef[1,1], sum.m218f$coef[1,1]+sum.m218f$coef[4,1], sum.m218f$coef[1,1]+sum.m218f$coef[3,1], sum.m218f$coef[1,1]+sum.m218f$coef[3,1]+sum.m218f$coef[4,1]+sum.m218f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m228a$coef[1,1], rep (NA, 5), sum.m228a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m228e$coef[c (1:2,4),1], rep (NA, 4), sum.m228e$coef[c (3,5),1], rep (NA, 5), sum.m228e$coef[1,1], sum.m228e$coef[1,1]+sum.m228e$coef[5,1], NA, sum.m228e$coef[1,1]+sum.m228e$coef[4,1])
  , c (sum.m228f$coef[c (1:2,4),1], rep (NA, 4), sum.m228f$coef[c (3,5),1], rep (NA, 2), sum.m228f$coef[6:8,1], sum.m228f$coef[1,1], sum.m228f$coef[1,1]+sum.m228f$coef[5,1], NA, sum.m228f$coef[1,1]+sum.m228f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m218g$coef[1:7,1], rep (NA, 2+5), sum.m218g$coef[1,1], sum.m218g$coef[1,1]+sum.m218g$coef[4,1], sum.m218g$coef[1,1]+sum.m218g$coef[3,1], sum.m218g$coef[1,1]+sum.m218g$coef[3,1]+sum.m218g$coef[4,1]+sum.m218g$coef[5,1])
  , c (sum.m228g$coef[c (1:2,4),1], rep (NA, 4), sum.m228g$coef[c (3,5),1], rep (NA, 5), sum.m228g$coef[1,1], sum.m228g$coef[1,1]+sum.m228g$coef[5,1], NA, sum.m228g$coef[1,1]+sum.m228g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m218i$coef[1:7,1], rep (NA, 2+5), sum.m218i$coef[1,1], sum.m218i$coef[1,1]+sum.m218i$coef[4,1], sum.m218i$coef[1,1]+sum.m218i$coef[3,1], sum.m218i$coef[1,1]+sum.m218i$coef[3,1]+sum.m218i$coef[4,1]+sum.m218i$coef[5,1])
  , c (sum.m228i$coef[c (1:2,4),1], rep (NA, 4), sum.m228i$coef[c (3,5:7),1], rep (NA, 3), sum.m228i$coef[1,1], sum.m228i$coef[1,1]+sum.m228i$coef[5,1], NA, sum.m228i$coef[1,1]+sum.m228i$coef[4,1])))
(seOutcome05a <- cbind (
  c (sum.m208a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m218a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m218c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m218c)[1,1])
       , sqrt (vcov (m218c)[1,1])
       , sqrt (vcov (m218c)[1,1]+1^2*vcov (m218c)[3,3]+2*1*vcov (m218c)[1,3])
       , sqrt (vcov (m218c)[1,1]+1^2*vcov (m218c)[3,3]+2*1*vcov (m218c)[1,3]))
  , c (sum.m218e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m218e)[1,1])
       , sqrt (vcov (m218e)[1,1]+1^2*vcov (m218e)[4,4]+2*1*vcov (m218e)[1,4])
       , sqrt (vcov (m218e)[1,1]+1^2*vcov (m218e)[3,3]+2*1*vcov (m218e)[1,3])
       , sqrt (vcov (m218e)[1,1]+1^2*vcov (m218e)[3,3]+1^2*vcov (m218e)[4,4]+1^2*1^2*vcov (m218e)[5,5]+2*1*vcov (m218e)[1,3]+2*1*vcov (m218e)[1,4]+2*1*1*vcov (m218e)[1,5]+2*1*1*vcov (m218e)[3,4]+2*1*1^2*vcov (m218e)[3,5]+2*1*1^2*vcov (m218e)[4,5]))
  , c (sum.m218f$coef[1:7,2], rep (NA, 2+2), sum.m218f$coef[8:10,2]
       , sqrt (vcov (m218f)[1,1])
       , sqrt (vcov (m218f)[1,1]+1^2*vcov (m218f)[4,4]+2*1*vcov (m218f)[1,4])
       , sqrt (vcov (m218f)[1,1]+1^2*vcov (m218f)[3,3]+2*1*vcov (m218f)[1,3])
       , sqrt (vcov (m218f)[1,1]+1^2*vcov (m218f)[3,3]+1^2*vcov (m218f)[4,4]+1^2*1^2*vcov (m218f)[5,5]+2*1*vcov (m218f)[1,3]+2*1*vcov (m218f)[1,4]+2*1*1*vcov (m218f)[1,5]+2*1*1*vcov (m218f)[3,4]+2*1*1^2*vcov (m218f)[3,5]+2*1*1^2*vcov (m218f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m228a$coef[1,2], rep (NA, 5), sum.m228a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m228e$coef[c (1:2,4),2], rep (NA, 4), sum.m228e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m228e)[1,1])
       , sqrt (vcov (m228e)[1,1]+1^2*vcov (m228e)[5,5]+2*1*vcov (m228e)[1,5])
       , NA
       , sqrt (vcov (m228e)[1,1]+1^2*vcov (m228e)[4,4]+2*1*vcov (m228e)[1,4]))
  , c (sum.m228f$coef[c (1:2,4),2], rep (NA, 4), sum.m228f$coef[c (3,5),2], rep (NA, 2), sum.m228f$coef[6:8,2]
       , sqrt (vcov (m228f)[1,1])
       , sqrt (vcov (m228f)[1,1]+1^2*vcov (m228f)[5,5]+2*1*vcov (m228f)[1,5])
       , NA
       , sqrt (vcov (m228f)[1,1]+1^2*vcov (m228f)[4,4]+2*1*vcov (m228f)[1,4]))
  , rep (NA, 18)
  , c (sum.m218g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m218g)[1,1])
       , sqrt (vcov (m218g)[1,1]+1^2*vcov (m218g)[4,4]+2*1*vcov (m218g)[1,4])
       , sqrt (vcov (m218g)[1,1]+1^2*vcov (m218g)[3,3]+2*1*vcov (m218g)[1,3])
       , sqrt (vcov (m218g)[1,1]+1^2*vcov (m218g)[3,3]+1^2*vcov (m218g)[4,4]+1^2*1^2*vcov (m218g)[5,5]+2*1*vcov (m218g)[1,3]+2*1*vcov (m218g)[1,4]+2*1*1*vcov (m218g)[1,5]+2*1*1*vcov (m218g)[3,4]+2*1*1^2*vcov (m218g)[3,5]+2*1*1^2*vcov (m218g)[4,5]))
  , c (sum.m228g$coef[c (1:2,4),2], rep (NA, 4), sum.m228g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m228g)[1,1])
       , sqrt (vcov (m228g)[1,1]+1^2*vcov (m228g)[5,5]+2*1*vcov (m228g)[1,5])
       , NA
       , sqrt (vcov (m228g)[1,1]+1^2*vcov (m228g)[4,4]+2*1*vcov (m228g)[1,4]))
  , rep (NA, 18)
  , c (sum.m218i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m218i)[1,1])
       , sqrt (vcov (m218i)[1,1]+1^2*vcov (m218i)[4,4]+2*1*vcov (m218i)[1,4])
       , sqrt (vcov (m218i)[1,1]+1^2*vcov (m218i)[3,3]+2*1*vcov (m218i)[1,3])
       , sqrt (vcov (m218i)[1,1]+1^2*vcov (m218i)[3,3]+1^2*vcov (m218i)[4,4]+1^2*1^2*vcov (m218i)[5,5]+2*1*vcov (m218i)[1,3]+2*1*vcov (m218i)[1,4]+2*1*1*vcov (m218i)[1,5]+2*1*1*vcov (m218i)[3,4]+2*1*1^2*vcov (m218i)[3,5]+2*1*1^2*vcov (m218i)[4,5]))
  , c (sum.m228i$coef[c (1:2,4),2], rep (NA, 4), sum.m228i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m228i)[1,1])
       , sqrt (vcov (m228i)[1,1]+1^2*vcov (m228i)[5,5]+2*1*vcov (m228i)[1,5])
       , NA
       , sqrt (vcov (m228i)[1,1]+1^2*vcov (m228i)[4,4]+2*1*vcov (m228i)[1,4]))))

odd <- seq (1, nrow (coefOutcome05a)*2, by=2); even <- seq (2, nrow (coefOutcome05a)*2, by=2)
(coefOutcome05tab <- data.frame (rbind (coefOutcome05a, seOutcome05a))) ## warnings reported. Don't worry
rownames (coefOutcome05tab) <- c (odd, even)
coefOutcome05tab <- coefOutcome05tab[order (as.numeric (rownames (coefOutcome05tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m208a$N, length (unique (sum.m208a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m208a$fe$year.f)))
  , c (sum.m218a$N, length (unique (sum.m218a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m218a$fe$year.f)))
  , c (sum.m218c$N, length (unique (sum.m218c$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m218c$fe$year.f)))
  , c (sum.m218e$N, length (unique (sum.m218e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m218e$fe$year.f)))
  , c (sum.m218f$N, length (unique (sum.m218f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m218f$fe$year.f)))
  , c (sum.m228a$N, length (unique (sum.m228a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m228a$fe$year.f)))
  , c (sum.m228e$N, length (unique (sum.m228e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m228e$fe$year.f)))
  , c (sum.m228f$N, length (unique (sum.m228f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m228f$fe$year.f)))
  , c (sum.m218g$N, length (unique (sum.m218g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m218g$fe$year.f)))
  , c (sum.m228g$N, length (unique (sum.m228g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m228g$fe$year.f)))
  , c (sum.m218i$N, length (unique (sum.m218i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m218i$fe$year.f)))
  , c (sum.m228i$N, length (unique (sum.m228i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m228i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (successful coup_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefOutcome05tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Alternative Outcomes (7): Successful coup"
               , label="T:rOutcomeCoupSuc")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (3.7.2) Figure A8

# (3.7.2.1) Marginal effect of growth (t-1) on Pr (successful coup t):

# creating the dataset for the plots
dPlotOutcome05g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotOutcome05g) <- "dataset"
dPlotOutcome05g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotOutcome05g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotOutcome05g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotOutcome05g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotOutcome05g$estimate <- c (coefOutcome05tab[c (29, 33, 31, 35),5], coefOutcome05tab[c (29, 33, 31, 35),9]
                               , coefOutcome05tab[c (29, 33, 31, 35),6], coefOutcome05tab[c (29, 33, 31, 35),10]
                               , coefOutcome05tab[c (29, 33, 31, 35),12], coefOutcome05tab[c (29, 33, 31, 35),13]
                               , coefOutcome05tab[c (29, 33, 31, 35),15], coefOutcome05tab[c (29, 33, 31, 35),16])
dPlotOutcome05g$se <- c (coefOutcome05tab[c (29, 33, 31, 35)+1,5], coefOutcome05tab[c (29, 33, 31, 35)+1,9]
                         , coefOutcome05tab[c (29, 33, 31, 35)+1,6], coefOutcome05tab[c (29, 33, 31, 35)+1,10]
                         , coefOutcome05tab[c (29, 33, 31, 35)+1,12], coefOutcome05tab[c (29, 33, 31, 35)+1,13]
                         , coefOutcome05tab[c (29, 33, 31, 35)+1,15], coefOutcome05tab[c (29, 33, 31, 35)+1,16])
dPlotOutcome05g$ciLow <- with (dPlotOutcome05g, estimate + se*qt (0.025, df=n))
dPlotOutcome05g$ciHigh <- with (dPlotOutcome05g, estimate + se*qt (0.975, df=n))
dPlotOutcome05g <- dPlotOutcome05g[!is.na (dPlotOutcome05g$estimate),]
dPlotOutcome05g$effect <- factor (dPlotOutcome05g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (3.7.2.2) Marginal effect of election (t) on Pr (successful coup t):
dPlotOutcome05el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotOutcome05el) <- "dataset"
dPlotOutcome05el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotOutcome05el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotOutcome05el$growth <- rep (seq (min (maddMain$madddGDPHead_lag), max (maddMain$madddGDPHead_lag), length.out=m), 3)
dPlotOutcome05el$estimate <- with (dPlotOutcome05el, ifelse (
  elType=="actual elections\n(closed)", sum.m218e$coef[2,1]+sum.m218e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m218e$coef[2,1]+sum.m218e$coef[7,1]+(sum.m218e$coef[3,1]+sum.m218e$coef[5,1])*growth, sum.m228e$coef[2,1]+sum.m228e$coef[4,1]*growth)))
dPlotOutcome05el$se <- with (dPlotOutcome05el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m218e)[2,2] + (growth^2)*vcov (m218e)[3,3] + (2*growth)*vcov (m218e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m218e)[2,2] + (growth^2)*vcov (m218e)[3,3] + (1^2)*vcov (m218e)[7,7] + (growth^2)*(1^2)*vcov (m218e)[5,5] + (2*growth)*vcov (m218e)[2,3] + (2*1)*vcov (m218e)[2,7] + (2*growth*1)*vcov (m218e)[2,5] + (2*growth*1)*vcov (m218e)[3,7] + (2*1*growth^2)*vcov (m218e)[3,5] + (2*growth*1^2)*vcov (m218e)[7,5]), sqrt (vcov (m228e)[2,2] + (growth^2)*vcov (m228e)[4,4] + (2*growth)*vcov (m228e)[2,4]))))
dPlotOutcome05el$ciLow <- with (dPlotOutcome05el, estimate + se*qt (0.025, df=n))
dPlotOutcome05el$ciHigh <- with (dPlotOutcome05el, estimate + se*qt (0.975, df=n))
dPlotOutcome05el <- dPlotOutcome05el[abs (dPlotOutcome05el$growth) <= h.lim,]

# (3.7.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectOutcomeCoupSuc01 <- ggplot (dPlotOutcome05g[dPlotOutcome05g$elType=="competitive\n& executive",]
                                    , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[successful coup (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectOutcomeCoupSuc02 <- ggplot (dPlotOutcome05g[dPlotOutcome05g$controls=="no controls",]
                                    , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[successful coup (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthOutcomeCoupSuc <- ggplot (maddMain[abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectOutcomeCoupSuc03 <- ggplot (dPlotOutcome05el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthOutcomeCoupSuc), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[successful coup (t)]"))

# (3.7.2.4) Exporting the plots
png ("Figures/fig_rOutcomeCoupSuc01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeCoupSuc01
dev.off ()
png ("Figures/fig_rOutcomeCoupSuc02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeCoupSuc02
dev.off ()
png ("Figures/fig_rOutcomeCoupSuc03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectOutcomeCoupSuc03
dev.off ()


## (3.8) Table A15
(coefOutcome06a <- cbind (
  c (sum.m209a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m219a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m219c$coef[1:3,1], rep (NA, 6+5), sum.m219c$coef[1,1], sum.m219c$coef[1,1], sum.m219c$coef[1,1]+sum.m219c$coef[3,1], sum.m219c$coef[1,1]+sum.m219c$coef[3,1])
  , c (sum.m219e$coef[1:7,1], rep (NA, 2+5), sum.m219e$coef[1,1], sum.m219e$coef[1,1]+sum.m219e$coef[4,1], sum.m219e$coef[1,1]+sum.m219e$coef[3,1], sum.m219e$coef[1,1]+sum.m219e$coef[3,1]+sum.m219e$coef[4,1]+sum.m219e$coef[5,1])
  , c (sum.m219f$coef[1:7,1], rep (NA, 2+2), sum.m219f$coef[8:10,1], sum.m219f$coef[1,1], sum.m219f$coef[1,1]+sum.m219f$coef[4,1], sum.m219f$coef[1,1]+sum.m219f$coef[3,1], sum.m219f$coef[1,1]+sum.m219f$coef[3,1]+sum.m219f$coef[4,1]+sum.m219f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m229a$coef[1,1], rep (NA, 5), sum.m229a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m229e$coef[c (1:2,4),1], rep (NA, 4), sum.m229e$coef[c (3,5),1], rep (NA, 5), sum.m229e$coef[1,1], sum.m229e$coef[1,1]+sum.m229e$coef[5,1], NA, sum.m229e$coef[1,1]+sum.m229e$coef[4,1])
  , c (sum.m229f$coef[c (1:2,4),1], rep (NA, 4), sum.m229f$coef[c (3,5),1], rep (NA, 2), sum.m229f$coef[6:8,1], sum.m229f$coef[1,1], sum.m229f$coef[1,1]+sum.m229f$coef[5,1], NA, sum.m229f$coef[1,1]+sum.m229f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m219g$coef[1:7,1], rep (NA, 2+5), sum.m219g$coef[1,1], sum.m219g$coef[1,1]+sum.m219g$coef[4,1], sum.m219g$coef[1,1]+sum.m219g$coef[3,1], sum.m219g$coef[1,1]+sum.m219g$coef[3,1]+sum.m219g$coef[4,1]+sum.m219g$coef[5,1])
  , c (sum.m229g$coef[c (1:2,4),1], rep (NA, 4), sum.m229g$coef[c (3,5),1], rep (NA, 5), sum.m229g$coef[1,1], sum.m229g$coef[1,1]+sum.m229g$coef[5,1], NA, sum.m229g$coef[1,1]+sum.m229g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m219i$coef[1:7,1], rep (NA, 2+5), sum.m219i$coef[1,1], sum.m219i$coef[1,1]+sum.m219i$coef[4,1], sum.m219i$coef[1,1]+sum.m219i$coef[3,1], sum.m219i$coef[1,1]+sum.m219i$coef[3,1]+sum.m219i$coef[4,1]+sum.m219i$coef[5,1])
  , c (sum.m229i$coef[c (1:2,4),1], rep (NA, 4), sum.m229i$coef[c (3,5:7),1], rep (NA, 3), sum.m229i$coef[1,1], sum.m229i$coef[1,1]+sum.m229i$coef[5,1], NA, sum.m229i$coef[1,1]+sum.m229i$coef[4,1])))
(seOutcome06a <- cbind (
  c (sum.m209a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m219a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m219c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m219c)[1,1])
       , sqrt (vcov (m219c)[1,1])
       , sqrt (vcov (m219c)[1,1]+1^2*vcov (m219c)[3,3]+2*1*vcov (m219c)[1,3])
       , sqrt (vcov (m219c)[1,1]+1^2*vcov (m219c)[3,3]+2*1*vcov (m219c)[1,3]))
  , c (sum.m219e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m219e)[1,1])
       , sqrt (vcov (m219e)[1,1]+1^2*vcov (m219e)[4,4]+2*1*vcov (m219e)[1,4])
       , sqrt (vcov (m219e)[1,1]+1^2*vcov (m219e)[3,3]+2*1*vcov (m219e)[1,3])
       , sqrt (vcov (m219e)[1,1]+1^2*vcov (m219e)[3,3]+1^2*vcov (m219e)[4,4]+1^2*1^2*vcov (m219e)[5,5]+2*1*vcov (m219e)[1,3]+2*1*vcov (m219e)[1,4]+2*1*1*vcov (m219e)[1,5]+2*1*1*vcov (m219e)[3,4]+2*1*1^2*vcov (m219e)[3,5]+2*1*1^2*vcov (m219e)[4,5]))
  , c (sum.m219f$coef[1:7,2], rep (NA, 2+2), sum.m219f$coef[8:10,2]
       , sqrt (vcov (m219f)[1,1])
       , sqrt (vcov (m219f)[1,1]+1^2*vcov (m219f)[4,4]+2*1*vcov (m219f)[1,4])
       , sqrt (vcov (m219f)[1,1]+1^2*vcov (m219f)[3,3]+2*1*vcov (m219f)[1,3])
       , sqrt (vcov (m219f)[1,1]+1^2*vcov (m219f)[3,3]+1^2*vcov (m219f)[4,4]+1^2*1^2*vcov (m219f)[5,5]+2*1*vcov (m219f)[1,3]+2*1*vcov (m219f)[1,4]+2*1*1*vcov (m219f)[1,5]+2*1*1*vcov (m219f)[3,4]+2*1*1^2*vcov (m219f)[3,5]+2*1*1^2*vcov (m219f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m229a$coef[1,2], rep (NA, 5), sum.m229a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m229e$coef[c (1:2,4),2], rep (NA, 4), sum.m229e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m229e)[1,1])
       , sqrt (vcov (m229e)[1,1]+1^2*vcov (m229e)[5,5]+2*1*vcov (m229e)[1,5])
       , NA
       , sqrt (vcov (m229e)[1,1]+1^2*vcov (m229e)[4,4]+2*1*vcov (m229e)[1,4]))
  , c (sum.m229f$coef[c (1:2,4),2], rep (NA, 4), sum.m229f$coef[c (3,5),2], rep (NA, 2), sum.m229f$coef[6:8,2]
       , sqrt (vcov (m229f)[1,1])
       , sqrt (vcov (m229f)[1,1]+1^2*vcov (m229f)[5,5]+2*1*vcov (m229f)[1,5])
       , NA
       , sqrt (vcov (m229f)[1,1]+1^2*vcov (m229f)[4,4]+2*1*vcov (m229f)[1,4]))
  , rep (NA, 18)
  , c (sum.m219g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m219g)[1,1])
       , sqrt (vcov (m219g)[1,1]+1^2*vcov (m219g)[4,4]+2*1*vcov (m219g)[1,4])
       , sqrt (vcov (m219g)[1,1]+1^2*vcov (m219g)[3,3]+2*1*vcov (m219g)[1,3])
       , sqrt (vcov (m219g)[1,1]+1^2*vcov (m219g)[3,3]+1^2*vcov (m219g)[4,4]+1^2*1^2*vcov (m219g)[5,5]+2*1*vcov (m219g)[1,3]+2*1*vcov (m219g)[1,4]+2*1*1*vcov (m219g)[1,5]+2*1*1*vcov (m219g)[3,4]+2*1*1^2*vcov (m219g)[3,5]+2*1*1^2*vcov (m219g)[4,5]))
  , c (sum.m229g$coef[c (1:2,4),2], rep (NA, 4), sum.m229g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m229g)[1,1])
       , sqrt (vcov (m229g)[1,1]+1^2*vcov (m229g)[5,5]+2*1*vcov (m229g)[1,5])
       , NA
       , sqrt (vcov (m229g)[1,1]+1^2*vcov (m229g)[4,4]+2*1*vcov (m229g)[1,4]))
  , rep (NA, 18)
  , c (sum.m219i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m219i)[1,1])
       , sqrt (vcov (m219i)[1,1]+1^2*vcov (m219i)[4,4]+2*1*vcov (m219i)[1,4])
       , sqrt (vcov (m219i)[1,1]+1^2*vcov (m219i)[3,3]+2*1*vcov (m219i)[1,3])
       , sqrt (vcov (m219i)[1,1]+1^2*vcov (m219i)[3,3]+1^2*vcov (m219i)[4,4]+1^2*1^2*vcov (m219i)[5,5]+2*1*vcov (m219i)[1,3]+2*1*vcov (m219i)[1,4]+2*1*1*vcov (m219i)[1,5]+2*1*1*vcov (m219i)[3,4]+2*1*1^2*vcov (m219i)[3,5]+2*1*1^2*vcov (m219i)[4,5]))
  , c (sum.m229i$coef[c (1:2,4),2], rep (NA, 4), sum.m229i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m229i)[1,1])
       , sqrt (vcov (m229i)[1,1]+1^2*vcov (m229i)[5,5]+2*1*vcov (m229i)[1,5])
       , NA
       , sqrt (vcov (m229i)[1,1]+1^2*vcov (m229i)[4,4]+2*1*vcov (m229i)[1,4]))))

odd <- seq (1, nrow (coefOutcome06a)*2, by=2); even <- seq (2, nrow (coefOutcome06a)*2, by=2)
(coefOutcome06tab <- data.frame (rbind (coefOutcome06a, seOutcome06a))) ## warnings reported. Don't worry
rownames (coefOutcome06tab) <- c (odd, even)
coefOutcome06tab <- coefOutcome06tab[order (as.numeric (rownames (coefOutcome06tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m209a$N, length (unique (sum.m209a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m209a$fe$year.f)))
  , c (sum.m219a$N, length (unique (sum.m219a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m219a$fe$year.f)))
  , c (sum.m219c$N, length (unique (sum.m219c$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m219c$fe$year.f)))
  , c (sum.m219e$N, length (unique (sum.m219e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m219e$fe$year.f)))
  , c (sum.m219f$N, length (unique (sum.m219f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m219f$fe$year.f)))
  , c (sum.m229a$N, length (unique (sum.m229a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m229a$fe$year.f)))
  , c (sum.m229e$N, length (unique (sum.m229e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m229e$fe$year.f)))
  , c (sum.m229f$N, length (unique (sum.m229f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m229f$fe$year.f)))
  , c (sum.m219g$N, length (unique (sum.m219g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m219g$fe$year.f)))
  , c (sum.m229g$N, length (unique (sum.m229g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m229g$fe$year.f)))
  , c (sum.m219i$N, length (unique (sum.m219i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m219i$fe$year.f)))
  , c (sum.m229i$N, length (unique (sum.m229i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m229i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (unsuccessful coup_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefOutcome06tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Alternative Outcomes (8): Unsuccessful coup"
               , label="T:rOutcomeCoupUnsuc")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (3.8.2) Figure A9

# (3.8.2.1) Marginal effect of growth (t-1) on Pr (unsuccessful coup t):

# creating the dataset for the plots
dPlotOutcome06g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotOutcome06g) <- "dataset"
dPlotOutcome06g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotOutcome06g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotOutcome06g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotOutcome06g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotOutcome06g$estimate <- c (coefOutcome06tab[c (29, 33, 31, 35),5], coefOutcome06tab[c (29, 33, 31, 35),9]
                               , coefOutcome06tab[c (29, 33, 31, 35),6], coefOutcome06tab[c (29, 33, 31, 35),10]
                               , coefOutcome06tab[c (29, 33, 31, 35),12], coefOutcome06tab[c (29, 33, 31, 35),13]
                               , coefOutcome06tab[c (29, 33, 31, 35),15], coefOutcome06tab[c (29, 33, 31, 35),16])
dPlotOutcome06g$se <- c (coefOutcome06tab[c (29, 33, 31, 35)+1,5], coefOutcome06tab[c (29, 33, 31, 35)+1,9]
                         , coefOutcome06tab[c (29, 33, 31, 35)+1,6], coefOutcome06tab[c (29, 33, 31, 35)+1,10]
                         , coefOutcome06tab[c (29, 33, 31, 35)+1,12], coefOutcome06tab[c (29, 33, 31, 35)+1,13]
                         , coefOutcome06tab[c (29, 33, 31, 35)+1,15], coefOutcome06tab[c (29, 33, 31, 35)+1,16])
dPlotOutcome06g$ciLow <- with (dPlotOutcome06g, estimate + se*qt (0.025, df=n))
dPlotOutcome06g$ciHigh <- with (dPlotOutcome06g, estimate + se*qt (0.975, df=n))
dPlotOutcome06g <- dPlotOutcome06g[!is.na (dPlotOutcome06g$estimate),]
dPlotOutcome06g$effect <- factor (dPlotOutcome06g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (3.8.2.2) Marginal effect of election (t) on Pr (unsuccessful coup t):
dPlotOutcome06el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotOutcome06el) <- "dataset"
dPlotOutcome06el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotOutcome06el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotOutcome06el$growth <- rep (seq (min (maddMain$madddGDPHead_lag), max (maddMain$madddGDPHead_lag), length.out=m), 3)
dPlotOutcome06el$estimate <- with (dPlotOutcome06el, ifelse (
  elType=="actual elections\n(closed)", sum.m219e$coef[2,1]+sum.m219e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m219e$coef[2,1]+sum.m219e$coef[7,1]+(sum.m219e$coef[3,1]+sum.m219e$coef[5,1])*growth, sum.m229e$coef[2,1]+sum.m229e$coef[4,1]*growth)))
dPlotOutcome06el$se <- with (dPlotOutcome06el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m219e)[2,2] + (growth^2)*vcov (m219e)[3,3] + (2*growth)*vcov (m219e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m219e)[2,2] + (growth^2)*vcov (m219e)[3,3] + (1^2)*vcov (m219e)[7,7] + (growth^2)*(1^2)*vcov (m219e)[5,5] + (2*growth)*vcov (m219e)[2,3] + (2*1)*vcov (m219e)[2,7] + (2*growth*1)*vcov (m219e)[2,5] + (2*growth*1)*vcov (m219e)[3,7] + (2*1*growth^2)*vcov (m219e)[3,5] + (2*growth*1^2)*vcov (m219e)[7,5]), sqrt (vcov (m229e)[2,2] + (growth^2)*vcov (m229e)[4,4] + (2*growth)*vcov (m229e)[2,4]))))
dPlotOutcome06el$ciLow <- with (dPlotOutcome06el, estimate + se*qt (0.025, df=n))
dPlotOutcome06el$ciHigh <- with (dPlotOutcome06el, estimate + se*qt (0.975, df=n))
dPlotOutcome06el <- dPlotOutcome06el[abs (dPlotOutcome06el$growth) <= h.lim,]

# (3.8.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectOutcomeCoupUnsuc01 <- ggplot (dPlotOutcome06g[dPlotOutcome06g$elType=="competitive\n& executive",]
                                      , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[unsuccessful coup (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectOutcomeCoupUnsuc02 <- ggplot (dPlotOutcome06g[dPlotOutcome06g$controls=="no controls",]
                                      , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[unsuccessful coup (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthOutcomeCoupUnsuc <- ggplot (maddMain[abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectOutcomeCoupUnsuc03 <- ggplot (dPlotOutcome06el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthOutcomeCoupUnsuc), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[unsuccessful coup (t)]"))

# (3.8.2.4) Exporting the plots
png ("Figures/fig_rOutcomeCoupUnsuc01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeCoupUnsuc01
dev.off ()
png ("Figures/fig_rOutcomeCoupUnsuc02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeCoupUnsuc02
dev.off ()
png ("Figures/fig_rOutcomeCoupUnsuc03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectOutcomeCoupUnsuc03
dev.off ()


## (3.9) Table A16
(coefOutcome07a <- cbind (
  c (sum.m203a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m213a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m213c$coef[1:3,1], rep (NA, 6+5), sum.m213c$coef[1,1], sum.m213c$coef[1,1], sum.m213c$coef[1,1]+sum.m213c$coef[3,1], sum.m213c$coef[1,1]+sum.m213c$coef[3,1])
  , c (sum.m213e$coef[1:7,1], rep (NA, 2+5), sum.m213e$coef[1,1], sum.m213e$coef[1,1]+sum.m213e$coef[4,1], sum.m213e$coef[1,1]+sum.m213e$coef[3,1], sum.m213e$coef[1,1]+sum.m213e$coef[3,1]+sum.m213e$coef[4,1]+sum.m213e$coef[5,1])
  , c (sum.m213f$coef[1:7,1], rep (NA, 2+2), sum.m213f$coef[8:10,1], sum.m213f$coef[1,1], sum.m213f$coef[1,1]+sum.m213f$coef[4,1], sum.m213f$coef[1,1]+sum.m213f$coef[3,1], sum.m213f$coef[1,1]+sum.m213f$coef[3,1]+sum.m213f$coef[4,1]+sum.m213f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m223a$coef[1,1], rep (NA, 5), sum.m223a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m223e$coef[c (1:2,4),1], rep (NA, 4), sum.m223e$coef[c (3,5),1], rep (NA, 5), sum.m223e$coef[1,1], sum.m223e$coef[1,1]+sum.m223e$coef[5,1], NA, sum.m223e$coef[1,1]+sum.m223e$coef[4,1])
  , c (sum.m223f$coef[c (1:2,4),1], rep (NA, 4), sum.m223f$coef[c (3,5),1], rep (NA, 2), sum.m223f$coef[6:8,1], sum.m223f$coef[1,1], sum.m223f$coef[1,1]+sum.m223f$coef[5,1], NA, sum.m223f$coef[1,1]+sum.m223f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m213g$coef[1:7,1], rep (NA, 2+5), sum.m213g$coef[1,1], sum.m213g$coef[1,1]+sum.m213g$coef[4,1], sum.m213g$coef[1,1]+sum.m213g$coef[3,1], sum.m213g$coef[1,1]+sum.m213g$coef[3,1]+sum.m213g$coef[4,1]+sum.m213g$coef[5,1])
  , c (sum.m223g$coef[c (1:2,4),1], rep (NA, 4), sum.m223g$coef[c (3,5),1], rep (NA, 5), sum.m223g$coef[1,1], sum.m223g$coef[1,1]+sum.m223g$coef[5,1], NA, sum.m223g$coef[1,1]+sum.m223g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m213i$coef[1:7,1], rep (NA, 2+5), sum.m213i$coef[1,1], sum.m213i$coef[1,1]+sum.m213i$coef[4,1], sum.m213i$coef[1,1]+sum.m213i$coef[3,1], sum.m213i$coef[1,1]+sum.m213i$coef[3,1]+sum.m213i$coef[4,1]+sum.m213i$coef[5,1])
  , c (sum.m223i$coef[c (1:2,4),1], rep (NA, 4), sum.m223i$coef[c (3,5:7),1], rep (NA, 3), sum.m223i$coef[1,1], sum.m223i$coef[1,1]+sum.m223i$coef[5,1], NA, sum.m223i$coef[1,1]+sum.m223i$coef[4,1])))
(seOutcome07a <- cbind (
  c (sum.m203a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m213a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m213c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m213c)[1,1])
       , sqrt (vcov (m213c)[1,1])
       , sqrt (vcov (m213c)[1,1]+1^2*vcov (m213c)[3,3]+2*1*vcov (m213c)[1,3])
       , sqrt (vcov (m213c)[1,1]+1^2*vcov (m213c)[3,3]+2*1*vcov (m213c)[1,3]))
  , c (sum.m213e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m213e)[1,1])
       , sqrt (vcov (m213e)[1,1]+1^2*vcov (m213e)[4,4]+2*1*vcov (m213e)[1,4])
       , sqrt (vcov (m213e)[1,1]+1^2*vcov (m213e)[3,3]+2*1*vcov (m213e)[1,3])
       , sqrt (vcov (m213e)[1,1]+1^2*vcov (m213e)[3,3]+1^2*vcov (m213e)[4,4]+1^2*1^2*vcov (m213e)[5,5]+2*1*vcov (m213e)[1,3]+2*1*vcov (m213e)[1,4]+2*1*1*vcov (m213e)[1,5]+2*1*1*vcov (m213e)[3,4]+2*1*1^2*vcov (m213e)[3,5]+2*1*1^2*vcov (m213e)[4,5]))
  , c (sum.m213f$coef[1:7,2], rep (NA, 2+2), sum.m213f$coef[8:10,2]
       , sqrt (vcov (m213f)[1,1])
       , sqrt (vcov (m213f)[1,1]+1^2*vcov (m213f)[4,4]+2*1*vcov (m213f)[1,4])
       , sqrt (vcov (m213f)[1,1]+1^2*vcov (m213f)[3,3]+2*1*vcov (m213f)[1,3])
       , sqrt (vcov (m213f)[1,1]+1^2*vcov (m213f)[3,3]+1^2*vcov (m213f)[4,4]+1^2*1^2*vcov (m213f)[5,5]+2*1*vcov (m213f)[1,3]+2*1*vcov (m213f)[1,4]+2*1*1*vcov (m213f)[1,5]+2*1*1*vcov (m213f)[3,4]+2*1*1^2*vcov (m213f)[3,5]+2*1*1^2*vcov (m213f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m223a$coef[1,2], rep (NA, 5), sum.m223a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m223e$coef[c (1:2,4),2], rep (NA, 4), sum.m223e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m223e)[1,1])
       , sqrt (vcov (m223e)[1,1]+1^2*vcov (m223e)[5,5]+2*1*vcov (m223e)[1,5])
       , NA
       , sqrt (vcov (m223e)[1,1]+1^2*vcov (m223e)[4,4]+2*1*vcov (m223e)[1,4]))
  , c (sum.m223f$coef[c (1:2,4),2], rep (NA, 4), sum.m223f$coef[c (3,5),2], rep (NA, 2), sum.m223f$coef[6:8,2]
       , sqrt (vcov (m223f)[1,1])
       , sqrt (vcov (m223f)[1,1]+1^2*vcov (m223f)[5,5]+2*1*vcov (m223f)[1,5])
       , NA
       , sqrt (vcov (m223f)[1,1]+1^2*vcov (m223f)[4,4]+2*1*vcov (m223f)[1,4]))
  , rep (NA, 18)
  , c (sum.m213g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m213g)[1,1])
       , sqrt (vcov (m213g)[1,1]+1^2*vcov (m213g)[4,4]+2*1*vcov (m213g)[1,4])
       , sqrt (vcov (m213g)[1,1]+1^2*vcov (m213g)[3,3]+2*1*vcov (m213g)[1,3])
       , sqrt (vcov (m213g)[1,1]+1^2*vcov (m213g)[3,3]+1^2*vcov (m213g)[4,4]+1^2*1^2*vcov (m213g)[5,5]+2*1*vcov (m213g)[1,3]+2*1*vcov (m213g)[1,4]+2*1*1*vcov (m213g)[1,5]+2*1*1*vcov (m213g)[3,4]+2*1*1^2*vcov (m213g)[3,5]+2*1*1^2*vcov (m213g)[4,5]))
  , c (sum.m223g$coef[c (1:2,4),2], rep (NA, 4), sum.m223g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m223g)[1,1])
       , sqrt (vcov (m223g)[1,1]+1^2*vcov (m223g)[5,5]+2*1*vcov (m223g)[1,5])
       , NA
       , sqrt (vcov (m223g)[1,1]+1^2*vcov (m223g)[4,4]+2*1*vcov (m223g)[1,4]))
  , rep (NA, 18)
  , c (sum.m213i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m213i)[1,1])
       , sqrt (vcov (m213i)[1,1]+1^2*vcov (m213i)[4,4]+2*1*vcov (m213i)[1,4])
       , sqrt (vcov (m213i)[1,1]+1^2*vcov (m213i)[3,3]+2*1*vcov (m213i)[1,3])
       , sqrt (vcov (m213i)[1,1]+1^2*vcov (m213i)[3,3]+1^2*vcov (m213i)[4,4]+1^2*1^2*vcov (m213i)[5,5]+2*1*vcov (m213i)[1,3]+2*1*vcov (m213i)[1,4]+2*1*1*vcov (m213i)[1,5]+2*1*1*vcov (m213i)[3,4]+2*1*1^2*vcov (m213i)[3,5]+2*1*1^2*vcov (m213i)[4,5]))
  , c (sum.m223i$coef[c (1:2,4),2], rep (NA, 4), sum.m223i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m223i)[1,1])
       , sqrt (vcov (m223i)[1,1]+1^2*vcov (m223i)[5,5]+2*1*vcov (m223i)[1,5])
       , NA
       , sqrt (vcov (m223i)[1,1]+1^2*vcov (m223i)[4,4]+2*1*vcov (m223i)[1,4]))))

odd <- seq (1, nrow (coefOutcome07a)*2, by=2); even <- seq (2, nrow (coefOutcome07a)*2, by=2)
(coefOutcome07tab <- data.frame (rbind (coefOutcome07a, seOutcome07a))) ## warnings reported. Don't worry
rownames (coefOutcome07tab) <- c (odd, even)
coefOutcome07tab <- coefOutcome07tab[order (as.numeric (rownames (coefOutcome07tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m203a$N, length (unique (sum.m203a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m203a$fe$year.f)))
  , c (sum.m213a$N, length (unique (sum.m213a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m213a$fe$year.f)))
  , c (sum.m213c$N, length (unique (sum.m213c$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m213c$fe$year.f)))
  , c (sum.m213e$N, length (unique (sum.m213e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m213e$fe$year.f)))
  , c (sum.m213f$N, length (unique (sum.m213f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m213f$fe$year.f)))
  , c (sum.m223a$N, length (unique (sum.m223a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m223a$fe$year.f)))
  , c (sum.m223e$N, length (unique (sum.m223e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m223e$fe$year.f)))
  , c (sum.m223f$N, length (unique (sum.m223f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m223f$fe$year.f)))
  , c (sum.m213g$N, length (unique (sum.m213g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m213g$fe$year.f)))
  , c (sum.m223g$N, length (unique (sum.m223g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m223g$fe$year.f)))
  , c (sum.m213i$N, length (unique (sum.m213i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m213i$fe$year.f)))
  , c (sum.m223i$N, length (unique (sum.m223i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m223i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (other autocracy_{t+1} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefOutcome07tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Alternative Outcomes (9): Another autocracy at $t+1$"
               , label="T:rOutcomeAutocracy")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (3.9.2) Figure A10

# (3.9.2.1) Marginal effect of growth (t-1) on Pr (other autocracy t+1):

# creating the dataset for the plots
dPlotOutcome07g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotOutcome07g) <- "dataset"
dPlotOutcome07g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotOutcome07g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotOutcome07g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotOutcome07g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotOutcome07g$estimate <- c (coefOutcome07tab[c (29, 33, 31, 35),5], coefOutcome07tab[c (29, 33, 31, 35),9]
                               , coefOutcome07tab[c (29, 33, 31, 35),6], coefOutcome07tab[c (29, 33, 31, 35),10]
                               , coefOutcome07tab[c (29, 33, 31, 35),12], coefOutcome07tab[c (29, 33, 31, 35),13]
                               , coefOutcome07tab[c (29, 33, 31, 35),15], coefOutcome07tab[c (29, 33, 31, 35),16])
dPlotOutcome07g$se <- c (coefOutcome07tab[c (29, 33, 31, 35)+1,5], coefOutcome07tab[c (29, 33, 31, 35)+1,9]
                         , coefOutcome07tab[c (29, 33, 31, 35)+1,6], coefOutcome07tab[c (29, 33, 31, 35)+1,10]
                         , coefOutcome07tab[c (29, 33, 31, 35)+1,12], coefOutcome07tab[c (29, 33, 31, 35)+1,13]
                         , coefOutcome07tab[c (29, 33, 31, 35)+1,15], coefOutcome07tab[c (29, 33, 31, 35)+1,16])
dPlotOutcome07g$ciLow <- with (dPlotOutcome07g, estimate + se*qt (0.025, df=n))
dPlotOutcome07g$ciHigh <- with (dPlotOutcome07g, estimate + se*qt (0.975, df=n))
dPlotOutcome07g <- dPlotOutcome07g[!is.na (dPlotOutcome07g$estimate),]
dPlotOutcome07g$effect <- factor (dPlotOutcome07g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (3.9.2.2) Marginal effect of election (t) on Pr (other autocracy t+1):
dPlotOutcome07el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotOutcome07el) <- "dataset"
dPlotOutcome07el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotOutcome07el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotOutcome07el$growth <- rep (seq (min (maddMain$madddGDPHead_lag), max (maddMain$madddGDPHead_lag), length.out=m), 3)
dPlotOutcome07el$estimate <- with (dPlotOutcome07el, ifelse (
  elType=="actual elections\n(closed)", sum.m213e$coef[2,1]+sum.m213e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m213e$coef[2,1]+sum.m213e$coef[7,1]+(sum.m213e$coef[3,1]+sum.m213e$coef[5,1])*growth, sum.m223e$coef[2,1]+sum.m223e$coef[4,1]*growth)))
dPlotOutcome07el$se <- with (dPlotOutcome07el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m213e)[2,2] + (growth^2)*vcov (m213e)[3,3] + (2*growth)*vcov (m213e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m213e)[2,2] + (growth^2)*vcov (m213e)[3,3] + (1^2)*vcov (m213e)[7,7] + (growth^2)*(1^2)*vcov (m213e)[5,5] + (2*growth)*vcov (m213e)[2,3] + (2*1)*vcov (m213e)[2,7] + (2*growth*1)*vcov (m213e)[2,5] + (2*growth*1)*vcov (m213e)[3,7] + (2*1*growth^2)*vcov (m213e)[3,5] + (2*growth*1^2)*vcov (m213e)[7,5]), sqrt (vcov (m223e)[2,2] + (growth^2)*vcov (m223e)[4,4] + (2*growth)*vcov (m223e)[2,4]))))
dPlotOutcome07el$ciLow <- with (dPlotOutcome07el, estimate + se*qt (0.025, df=n))
dPlotOutcome07el$ciHigh <- with (dPlotOutcome07el, estimate + se*qt (0.975, df=n))
dPlotOutcome07el <- dPlotOutcome07el[abs (dPlotOutcome07el$growth) <= h.lim,]

# (3.9.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectOutcomeAutocracy01 <- ggplot (dPlotOutcome07g[dPlotOutcome07g$elType=="competitive\n& executive",]
                                      , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[other autocracy (t+1)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectOutcomeAutocracy02 <- ggplot (dPlotOutcome07g[dPlotOutcome07g$controls=="no controls",]
                                      , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[other autocracy (t+1)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthOutcomeAutocracy <- ggplot (maddMain[abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectOutcomeAutocracy03 <- ggplot (dPlotOutcome07el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthOutcomeAutocracy), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[other autocracy (t+1)]"))

# (3.9.2.4) Exporting the plots
png ("Figures/fig_rOutcomeAutocracy01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeAutocracy01
dev.off ()
png ("Figures/fig_rOutcomeAutocracy02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeAutocracy02
dev.off ()
png ("Figures/fig_rOutcomeAutocracy03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectOutcomeAutocracy03
dev.off ()


## (3.10) Table A17
(coefOutcome08a <- cbind (
  c (sum.m202a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m212a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m212c$coef[1:3,1], rep (NA, 6+5), sum.m212c$coef[1,1], sum.m212c$coef[1,1], sum.m212c$coef[1,1]+sum.m212c$coef[3,1], sum.m212c$coef[1,1]+sum.m212c$coef[3,1])
  , c (sum.m212e$coef[1:7,1], rep (NA, 2+5), sum.m212e$coef[1,1], sum.m212e$coef[1,1]+sum.m212e$coef[4,1], sum.m212e$coef[1,1]+sum.m212e$coef[3,1], sum.m212e$coef[1,1]+sum.m212e$coef[3,1]+sum.m212e$coef[4,1]+sum.m212e$coef[5,1])
  , c (sum.m212f$coef[1:7,1], rep (NA, 2+2), sum.m212f$coef[8:10,1], sum.m212f$coef[1,1], sum.m212f$coef[1,1]+sum.m212f$coef[4,1], sum.m212f$coef[1,1]+sum.m212f$coef[3,1], sum.m212f$coef[1,1]+sum.m212f$coef[3,1]+sum.m212f$coef[4,1]+sum.m212f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m222a$coef[1,1], rep (NA, 5), sum.m222a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m222e$coef[c (1:2,4),1], rep (NA, 4), sum.m222e$coef[c (3,5),1], rep (NA, 5), sum.m222e$coef[1,1], sum.m222e$coef[1,1]+sum.m222e$coef[5,1], NA, sum.m222e$coef[1,1]+sum.m222e$coef[4,1])
  , c (sum.m222f$coef[c (1:2,4),1], rep (NA, 4), sum.m222f$coef[c (3,5),1], rep (NA, 2), sum.m222f$coef[6:8,1], sum.m222f$coef[1,1], sum.m222f$coef[1,1]+sum.m222f$coef[5,1], NA, sum.m222f$coef[1,1]+sum.m222f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m212g$coef[1:7,1], rep (NA, 2+5), sum.m212g$coef[1,1], sum.m212g$coef[1,1]+sum.m212g$coef[4,1], sum.m212g$coef[1,1]+sum.m212g$coef[3,1], sum.m212g$coef[1,1]+sum.m212g$coef[3,1]+sum.m212g$coef[4,1]+sum.m212g$coef[5,1])
  , c (sum.m222g$coef[c (1:2,4),1], rep (NA, 4), sum.m222g$coef[c (3,5),1], rep (NA, 5), sum.m222g$coef[1,1], sum.m222g$coef[1,1]+sum.m222g$coef[5,1], NA, sum.m222g$coef[1,1]+sum.m222g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m212i$coef[1:7,1], rep (NA, 2+5), sum.m212i$coef[1,1], sum.m212i$coef[1,1]+sum.m212i$coef[4,1], sum.m212i$coef[1,1]+sum.m212i$coef[3,1], sum.m212i$coef[1,1]+sum.m212i$coef[3,1]+sum.m212i$coef[4,1]+sum.m212i$coef[5,1])
  , c (sum.m222i$coef[c (1:2,4),1], rep (NA, 4), sum.m222i$coef[c (3,5:7),1], rep (NA, 3), sum.m222i$coef[1,1], sum.m222i$coef[1,1]+sum.m222i$coef[5,1], NA, sum.m222i$coef[1,1]+sum.m222i$coef[4,1])))
(seOutcome08a <- cbind (
  c (sum.m202a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m212a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m212c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m212c)[1,1])
       , sqrt (vcov (m212c)[1,1])
       , sqrt (vcov (m212c)[1,1]+1^2*vcov (m212c)[3,3]+2*1*vcov (m212c)[1,3])
       , sqrt (vcov (m212c)[1,1]+1^2*vcov (m212c)[3,3]+2*1*vcov (m212c)[1,3]))
  , c (sum.m212e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m212e)[1,1])
       , sqrt (vcov (m212e)[1,1]+1^2*vcov (m212e)[4,4]+2*1*vcov (m212e)[1,4])
       , sqrt (vcov (m212e)[1,1]+1^2*vcov (m212e)[3,3]+2*1*vcov (m212e)[1,3])
       , sqrt (vcov (m212e)[1,1]+1^2*vcov (m212e)[3,3]+1^2*vcov (m212e)[4,4]+1^2*1^2*vcov (m212e)[5,5]+2*1*vcov (m212e)[1,3]+2*1*vcov (m212e)[1,4]+2*1*1*vcov (m212e)[1,5]+2*1*1*vcov (m212e)[3,4]+2*1*1^2*vcov (m212e)[3,5]+2*1*1^2*vcov (m212e)[4,5]))
  , c (sum.m212f$coef[1:7,2], rep (NA, 2+2), sum.m212f$coef[8:10,2]
       , sqrt (vcov (m212f)[1,1])
       , sqrt (vcov (m212f)[1,1]+1^2*vcov (m212f)[4,4]+2*1*vcov (m212f)[1,4])
       , sqrt (vcov (m212f)[1,1]+1^2*vcov (m212f)[3,3]+2*1*vcov (m212f)[1,3])
       , sqrt (vcov (m212f)[1,1]+1^2*vcov (m212f)[3,3]+1^2*vcov (m212f)[4,4]+1^2*1^2*vcov (m212f)[5,5]+2*1*vcov (m212f)[1,3]+2*1*vcov (m212f)[1,4]+2*1*1*vcov (m212f)[1,5]+2*1*1*vcov (m212f)[3,4]+2*1*1^2*vcov (m212f)[3,5]+2*1*1^2*vcov (m212f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m222a$coef[1,2], rep (NA, 5), sum.m222a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m222e$coef[c (1:2,4),2], rep (NA, 4), sum.m222e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m222e)[1,1])
       , sqrt (vcov (m222e)[1,1]+1^2*vcov (m222e)[5,5]+2*1*vcov (m222e)[1,5])
       , NA
       , sqrt (vcov (m222e)[1,1]+1^2*vcov (m222e)[4,4]+2*1*vcov (m222e)[1,4]))
  , c (sum.m222f$coef[c (1:2,4),2], rep (NA, 4), sum.m222f$coef[c (3,5),2], rep (NA, 2), sum.m222f$coef[6:8,2]
       , sqrt (vcov (m222f)[1,1])
       , sqrt (vcov (m222f)[1,1]+1^2*vcov (m222f)[5,5]+2*1*vcov (m222f)[1,5])
       , NA
       , sqrt (vcov (m222f)[1,1]+1^2*vcov (m222f)[4,4]+2*1*vcov (m222f)[1,4]))
  , rep (NA, 18)
  , c (sum.m212g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m212g)[1,1])
       , sqrt (vcov (m212g)[1,1]+1^2*vcov (m212g)[4,4]+2*1*vcov (m212g)[1,4])
       , sqrt (vcov (m212g)[1,1]+1^2*vcov (m212g)[3,3]+2*1*vcov (m212g)[1,3])
       , sqrt (vcov (m212g)[1,1]+1^2*vcov (m212g)[3,3]+1^2*vcov (m212g)[4,4]+1^2*1^2*vcov (m212g)[5,5]+2*1*vcov (m212g)[1,3]+2*1*vcov (m212g)[1,4]+2*1*1*vcov (m212g)[1,5]+2*1*1*vcov (m212g)[3,4]+2*1*1^2*vcov (m212g)[3,5]+2*1*1^2*vcov (m212g)[4,5]))
  , c (sum.m222g$coef[c (1:2,4),2], rep (NA, 4), sum.m222g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m222g)[1,1])
       , sqrt (vcov (m222g)[1,1]+1^2*vcov (m222g)[5,5]+2*1*vcov (m222g)[1,5])
       , NA
       , sqrt (vcov (m222g)[1,1]+1^2*vcov (m222g)[4,4]+2*1*vcov (m222g)[1,4]))
  , rep (NA, 18)
  , c (sum.m212i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m212i)[1,1])
       , sqrt (vcov (m212i)[1,1]+1^2*vcov (m212i)[4,4]+2*1*vcov (m212i)[1,4])
       , sqrt (vcov (m212i)[1,1]+1^2*vcov (m212i)[3,3]+2*1*vcov (m212i)[1,3])
       , sqrt (vcov (m212i)[1,1]+1^2*vcov (m212i)[3,3]+1^2*vcov (m212i)[4,4]+1^2*1^2*vcov (m212i)[5,5]+2*1*vcov (m212i)[1,3]+2*1*vcov (m212i)[1,4]+2*1*1*vcov (m212i)[1,5]+2*1*1*vcov (m212i)[3,4]+2*1*1^2*vcov (m212i)[3,5]+2*1*1^2*vcov (m212i)[4,5]))
  , c (sum.m222i$coef[c (1:2,4),2], rep (NA, 4), sum.m222i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m222i)[1,1])
       , sqrt (vcov (m222i)[1,1]+1^2*vcov (m222i)[5,5]+2*1*vcov (m222i)[1,5])
       , NA
       , sqrt (vcov (m222i)[1,1]+1^2*vcov (m222i)[4,4]+2*1*vcov (m222i)[1,4]))))

odd <- seq (1, nrow (coefOutcome08a)*2, by=2); even <- seq (2, nrow (coefOutcome08a)*2, by=2)
(coefOutcome08tab <- data.frame (rbind (coefOutcome08a, seOutcome08a))) ## warnings reported. Don't worry
rownames (coefOutcome08tab) <- c (odd, even)
coefOutcome08tab <- coefOutcome08tab[order (as.numeric (rownames (coefOutcome08tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m202a$N, length (unique (sum.m202a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m202a$fe$year.f)))
  , c (sum.m212a$N, length (unique (sum.m212a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m212a$fe$year.f)))
  , c (sum.m212c$N, length (unique (sum.m212c$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m212c$fe$year.f)))
  , c (sum.m212e$N, length (unique (sum.m212e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m212e$fe$year.f)))
  , c (sum.m212f$N, length (unique (sum.m212f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m212f$fe$year.f)))
  , c (sum.m222a$N, length (unique (sum.m222a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m222a$fe$year.f)))
  , c (sum.m222e$N, length (unique (sum.m222e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m222e$fe$year.f)))
  , c (sum.m222f$N, length (unique (sum.m222f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m222f$fe$year.f)))
  , c (sum.m212g$N, length (unique (sum.m212g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m212g$fe$year.f)))
  , c (sum.m222g$N, length (unique (sum.m222g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m222g$fe$year.f)))
  , c (sum.m212i$N, length (unique (sum.m212i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m212i$fe$year.f)))
  , c (sum.m222i$N, length (unique (sum.m222i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m222i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (democracy_{t+1} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefOutcome08tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Alternative Outcomes (10): Democracy (or provisional government) at $t+1$"
               , label="T:rOutcomeDemocracy")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (3.10.2) Figure A11

# (3.10.2.1) Marginal effect of growth (t-1) on Pr (democracy t+1):

# creating the dataset for the plots
dPlotOutcome08g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotOutcome08g) <- "dataset"
dPlotOutcome08g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotOutcome08g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotOutcome08g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotOutcome08g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotOutcome08g$estimate <- c (coefOutcome08tab[c (29, 33, 31, 35),5], coefOutcome08tab[c (29, 33, 31, 35),9]
                               , coefOutcome08tab[c (29, 33, 31, 35),6], coefOutcome08tab[c (29, 33, 31, 35),10]
                               , coefOutcome08tab[c (29, 33, 31, 35),12], coefOutcome08tab[c (29, 33, 31, 35),13]
                               , coefOutcome08tab[c (29, 33, 31, 35),15], coefOutcome08tab[c (29, 33, 31, 35),16])
dPlotOutcome08g$se <- c (coefOutcome08tab[c (29, 33, 31, 35)+1,5], coefOutcome08tab[c (29, 33, 31, 35)+1,9]
                         , coefOutcome08tab[c (29, 33, 31, 35)+1,6], coefOutcome08tab[c (29, 33, 31, 35)+1,10]
                         , coefOutcome08tab[c (29, 33, 31, 35)+1,12], coefOutcome08tab[c (29, 33, 31, 35)+1,13]
                         , coefOutcome08tab[c (29, 33, 31, 35)+1,15], coefOutcome08tab[c (29, 33, 31, 35)+1,16])
dPlotOutcome08g$ciLow <- with (dPlotOutcome08g, estimate + se*qt (0.025, df=n))
dPlotOutcome08g$ciHigh <- with (dPlotOutcome08g, estimate + se*qt (0.975, df=n))
dPlotOutcome08g <- dPlotOutcome08g[!is.na (dPlotOutcome08g$estimate),]
dPlotOutcome08g$effect <- factor (dPlotOutcome08g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (3.10.2.2) Marginal effect of election (t) on Pr (democracy t+1):
dPlotOutcome08el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotOutcome08el) <- "dataset"
dPlotOutcome08el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotOutcome08el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotOutcome08el$growth <- rep (seq (min (maddMain$madddGDPHead_lag), max (maddMain$madddGDPHead_lag), length.out=m), 3)
dPlotOutcome08el$estimate <- with (dPlotOutcome08el, ifelse (
  elType=="actual elections\n(closed)", sum.m212e$coef[2,1]+sum.m212e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m212e$coef[2,1]+sum.m212e$coef[7,1]+(sum.m212e$coef[3,1]+sum.m212e$coef[5,1])*growth, sum.m222e$coef[2,1]+sum.m222e$coef[4,1]*growth)))
dPlotOutcome08el$se <- with (dPlotOutcome08el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m212e)[2,2] + (growth^2)*vcov (m212e)[3,3] + (2*growth)*vcov (m212e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m212e)[2,2] + (growth^2)*vcov (m212e)[3,3] + (1^2)*vcov (m212e)[7,7] + (growth^2)*(1^2)*vcov (m212e)[5,5] + (2*growth)*vcov (m212e)[2,3] + (2*1)*vcov (m212e)[2,7] + (2*growth*1)*vcov (m212e)[2,5] + (2*growth*1)*vcov (m212e)[3,7] + (2*1*growth^2)*vcov (m212e)[3,5] + (2*growth*1^2)*vcov (m212e)[7,5]), sqrt (vcov (m222e)[2,2] + (growth^2)*vcov (m222e)[4,4] + (2*growth)*vcov (m222e)[2,4]))))
dPlotOutcome08el$ciLow <- with (dPlotOutcome08el, estimate + se*qt (0.025, df=n))
dPlotOutcome08el$ciHigh <- with (dPlotOutcome08el, estimate + se*qt (0.975, df=n))
dPlotOutcome08el <- dPlotOutcome08el[abs (dPlotOutcome08el$growth) <= h.lim,]

# (3.10.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectOutcomeDemocracy01 <- ggplot (dPlotOutcome08g[dPlotOutcome08g$elType=="competitive\n& executive",]
                                      , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[democracy (t+1)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectOutcomeDemocracy02 <- ggplot (dPlotOutcome08g[dPlotOutcome08g$controls=="no controls",]
                                      , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[democracy (t+1)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthOutcomeDemocracy <- ggplot (maddMain[abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectOutcomeDemocracy03 <- ggplot (dPlotOutcome08el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthOutcomeDemocracy), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[democracy (t+1)]"))

# (3.10.2.4) Exporting the plots
png ("Figures/fig_rOutcomeDemocracy01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeDemocracy01
dev.off ()
png ("Figures/fig_rOutcomeDemocracy02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectOutcomeDemocracy02
dev.off ()
png ("Figures/fig_rOutcomeDemocracy03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectOutcomeDemocracy03
dev.off ()


## (2.11) Table A18
(coefManipulation01a <- cbind (
  c (coef.m701a[2,1], rep (NA, 7), coef.m701a[1,1], coef.m721a[2:4,1], rep (NA, 7), coef.m721a[1,1])
  , c (coef.m701c[c (2:9,1),1], coef.m721c[c (2:11,1),1])
  , c (sum.m701d$coef[1,1], rep (NA, 7+1), sum.m721d$coef[1:3,1], rep (NA, 7+1))
  , rep (NA, 20)
  , c (sum.m702a$coef[2,1], rep (NA, 7), sum.m702a$coef[1,1], sum.m722a$coef[2:4,1], rep (NA, 7), sum.m722a$coef[1,1])
  , c (sum.m702c$coef[c (2:9,1),1], sum.m722c$coef[c (2:11,1),1])
  , c (sum.m702d$coef[1,1], rep (NA, 7+1), sum.m722d$coef[1:3,1], rep (NA, 7+1))
  , rep (NA, 20)
  , c (sum.m703a$coef[2,1], rep (NA, 7), sum.m703a$coef[1,1], sum.m723a$coef[2:4,1], rep (NA, 7), sum.m723a$coef[1,1])
  , c (sum.m703c$coef[c (2:9,1),1], sum.m723c$coef[c (2:11,1),1])
  , c (sum.m703d$coef[1,1], rep (NA, 7+1), sum.m723d$coef[1:3,1], rep (NA, 7+1))
  , rep (NA, 20)
  , c (sum.m704a$coef[2,1], rep (NA, 7), sum.m704a$coef[1,1], sum.m724a$coef[2:4,1], rep (NA, 7), sum.m724a$coef[1,1])
  , c (sum.m704c$coef[c (2:9,1),1], sum.m724c$coef[c (2:11,1),1])
  , c (sum.m704d$coef[1,1], rep (NA, 7+1), sum.m724d$coef[1:3,1], rep (NA, 7+1))))
(seManipulation01a <- cbind (
  c (coef.m701a[2,2], rep (NA, 7), coef.m701a[1,2], coef.m721a[2:4,2], rep (NA, 7), coef.m721a[1,2])
  , c (coef.m701c[c (2:9,1),2], coef.m721c[c (2:11,1),2])
  , c (sum.m701d$coef[1,2], rep (NA, 7+1), sum.m721d$coef[1:3,2], rep (NA, 7+1))
  , rep (NA, 20)
  , c (sum.m702a$coef[2,2], rep (NA, 7), sum.m702a$coef[1,2], sum.m722a$coef[2:4,2], rep (NA, 7), sum.m722a$coef[1,2])
  , c (sum.m702c$coef[c (2:9,1),2], sum.m722c$coef[c (2:11,1),2])
  , c (sum.m702d$coef[1,2], rep (NA, 7+1), sum.m722d$coef[1:3,2], rep (NA, 7+1))
  , rep (NA, 20)
  , c (sum.m703a$coef[2,2], rep (NA, 7), sum.m703a$coef[1,2], sum.m723a$coef[2:4,2], rep (NA, 7), sum.m723a$coef[1,2])
  , c (sum.m703c$coef[c (2:9,1),2], sum.m723c$coef[c (2:11,1),2])
  , c (sum.m703d$coef[1,2], rep (NA, 7+1), sum.m723d$coef[1:3,2], rep (NA, 7+1))
  , rep (NA, 20)
  , c (sum.m704a$coef[2,2], rep (NA, 7), sum.m704a$coef[1,2], sum.m724a$coef[2:4,2], rep (NA, 7), sum.m724a$coef[1,2])
  , c (sum.m704c$coef[c (2:9,1),2], sum.m724c$coef[c (2:11,1),2])
  , c (sum.m704d$coef[1,2], rep (NA, 7+1), sum.m724d$coef[1:3,2], rep (NA, 7+1))))

odd <- seq (1, nrow (coefManipulation01a)*2, by=2); even <- seq (2, nrow (coefManipulation01a)*2, by=2)
(coefManipulation01tab <- data.frame (rbind (coefManipulation01a, seManipulation01a))) ## warnings reported. Don't worry
rownames (coefManipulation01tab) <- c (odd, even)
coefManipulation01tab <- coefManipulation01tab[order (as.numeric (rownames (coefManipulation01tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", ""
           , "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$", "\\emph{party-based regime}", "", "\\emph{military regime}", "", "\\emph{personalist regime}", "", "\\emph{Cold War}$_{t}$", "", "(Intercept)", ""
           , "\\emph{growth}$_{t-1}$", "", "\\emph{breakdown}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{breakdown}$_{t}$", ""
           , "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$", "\\emph{party-based regime}", "", "\\emph{military regime}", "", "\\emph{personalist regime}", "", "\\emph{Cold War}$_{t}$", "", "(Intercept)", "")

(Ns00 <- cbind (
  c (sum.m701a$df[1]+sum.m701a$df[2], length (unique (maddMain[!is.na (maddMain$nHarassment) & maddMain$comE==1,]$idRegime)), length (unique (maddMain[!is.na (maddMain$nHarassment) & maddMain$comE==1,]$country)))
  , c (sum.m701c$df[1]+sum.m701c$df[2], length (unique (maddMain[!is.na (maddMain$nHarassment) & maddMain$comE==1,]$idRegime)), length (unique (maddMain[!is.na (maddMain$nHarassment) & maddMain$comE==1,]$country)))
  , c (sum.m701d$N, length (unique (sum.m701d$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$nHarassment) & maddMain$comE==1,]$country)))
  , c (sum.m702a$N, length (unique (sum.m702d$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$v2elfrfair) & maddMain$comE==1,]$country)))
  , c (sum.m702c$N, length (unique (sum.m702d$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$v2elfrfair) & maddMain$comE==1,]$country)))
  , c (sum.m702d$N, length (unique (sum.m702d$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$v2elfrfair) & maddMain$comE==1,]$country)))
  , c (sum.m703a$N, length (unique (sum.m703d$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$v2elirreg) & maddMain$comE==1,]$country)))
  , c (sum.m703c$N, length (unique (sum.m703d$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$v2elirreg) & maddMain$comE==1,]$country)))
  , c (sum.m703d$N, length (unique (sum.m703d$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$v2elirreg) & maddMain$comE==1,]$country)))
  , c (sum.m704a$N, length (unique (sum.m704d$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$v2elintim) & maddMain$comE==1,]$country)))
  , c (sum.m704c$N, length (unique (sum.m704d$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$v2elintim) & maddMain$comE==1,]$country)))
  , c (sum.m704d$N, length (unique (sum.m704d$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$v2elintim) & maddMain$comE==1,]$country)))))

Header1 <- paste ("\\toprule & \\multicolumn{3}{c}{\\textbf{harassment}} & & \\multicolumn{3}{c}{\\textbf{free and fair}} & & \\multicolumn{3}{c}{\\textbf{irregularities}} & & \\multicolumn{3}{c}{\\textbf{intimidation}} \\\\ \n")
Header2 <- paste ("& \\multicolumn{3}{c}{\\textbf{(NELDA)}} & & \\multicolumn{3}{c}{\\textbf{(V-Dem)}} & & \\multicolumn{3}{c}{\\textbf{(V-Dem)}} & & \\multicolumn{3}{c}{\\textbf{(V-Dem)}} \\\\ \\cmidrule{2-4} \\cmidrule{6-8} \\cmidrule{10-12} \\cmidrule{14-16} \n")
Header3 <- paste ("\\multicolumn{1}{l}{(a) \\emph{\\emph{growth}$_{t-1}$ only}} & \\multicolumn{1}{c}{(1)} & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & \\multicolumn{1}{c}{(6)} & & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & \\multicolumn{1}{c}{(9)} & & \\multicolumn{1}{c}{(10)} & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header4 <- paste ("[2ex] \\multicolumn{16}{l}{(b) \\emph{Conditioning on \\emph{breakdown}$_{t}$}} \\\\ \\midrule \n")

add.model <- paste ("\\midrule specification & \\multicolumn{1}{c}{probit} & \\multicolumn{1}{c}{probit} & \\multicolumn{1}{c}{OLS} & & \\multicolumn{1}{c}{OLS} & \\multicolumn{1}{c}{OLS} & \\multicolumn{1}{c}{OLS} & & \\multicolumn{1}{c}{OLS} & \\multicolumn{1}{c}{OLS} & \\multicolumn{1}{c}{OLS} & & \\multicolumn{1}{c}{OLS} & \\multicolumn{1}{c}{OLS} & \\multicolumn{1}{c}{OLS} \\\\ \n")
add.region <- paste ("region FEs & \\multicolumn{1}{c}{no} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{no} & & \\multicolumn{1}{c}{no} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{no} & & \\multicolumn{1}{c}{no} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{no} & & \\multicolumn{1}{c}{no} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{no} \\\\ \n")
add.regime <- paste ("regime FEs & \\multicolumn{1}{c}{no} & \\multicolumn{1}{c}{no} & \\multicolumn{1}{c}{yes} & & \\multicolumn{1}{c}{no} & \\multicolumn{1}{c}{no} & \\multicolumn{1}{c}{yes} & & \\multicolumn{1}{c}{no} & \\multicolumn{1}{c}{no} & \\multicolumn{1}{c}{yes} & & \\multicolumn{1}{c}{no} & \\multicolumn{1}{c}{no} & \\multicolumn{1}{c}{yes} \\\\ \n")
n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 18
addtorow$pos[[5]] <- 40
addtorow$pos[[6]] <- 40
addtorow$pos[[7]] <- 40
addtorow$pos[[8]] <- 40
addtorow$pos[[9]] <- 40
addtorow$pos[[10]] <- 40
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , add.model, add.region, add.regime
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefManipulation01tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Alternative Outcomes (9): Electoral manipulation"
               , label="T:rOutcomeManipulation")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)


## (2.12) Table 2
(coefOutcome11tab <- as.data.frame (rbind (
  cbind (coefOutcome01tab[29:36,c (5,9)], rep (NA, 8), coefOutcome02tab[29:36,c (5,9)], rep (NA, 8), coefOutcome03tab[29:36,c (5,9)], rep (NA, 8), coefOutcome09tab[29:36,c (5,9)], rep (NA, 8), coefOutcome10tab[29:36,c (5,9)])
  , cbind (coefOutcome04tab[29:36,c (5,9)], rep (NA, 8), coefOutcome05tab[29:36,c (5,9)], rep (NA, 8), coefOutcome06tab[29:36,c (5,9)], rep (NA, 8), coefOutcome07tab[29:36,c (5,9)], rep (NA, 8), coefOutcome08tab[29:36,c (5,9)]))))
colnames (coefOutcome11tab) <- paste ("X", 1:ncol (coefOutcome11tab), sep="")
coefOutcome11tab$X3 <- as.numeric (coefOutcome11tab$X3)
coefOutcome11tab$X6 <- as.numeric (coefOutcome11tab$X6)
coefOutcome11tab$X9 <- as.numeric (coefOutcome11tab$X9)
coefOutcome11tab$X12 <- as.numeric (coefOutcome11tab$X12)

rows <- rep (c ("no election (cl.)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", ""), 2)

Header1a <- paste ("\\toprule & \\multicolumn{2}{c}{\\textbf{\\emph{end (insider)}$_{t}$}} & & \\multicolumn{2}{c}{\\textbf{\\emph{end (outsider)}$_{t}$}} & & \\multicolumn{2}{c}{\\textbf{\\emph{end (voluntary)}$_{t}$}} & & \\multicolumn{2}{c}{\\textbf{\\emph{protest}$_{t}$}} & & \\multicolumn{2}{c}{\\textbf{\\emph{violent protest}$_{t}$}} \\ \\cmidrule{2-3} \\cmidrule{5-6} \\cmidrule{8-9} \\cmidrule{11-12} \\cmidrule{14-15} \n")
Header1b <- paste ("[2ex] & \\multicolumn{2}{c}{\\textbf{\\emph{coup attempt}$_{t}$}} & & \\multicolumn{2}{c}{\\textbf{\\emph{successful coup}$_{t}$}} & & \\multicolumn{2}{c}{\\textbf{\\emph{unsuc. coup}$_{t}$}} & & \\multicolumn{2}{c}{\\textbf{\\emph{other autocracy}$_{t+1}$}} & & \\multicolumn{2}{c}{\\textbf{\\emph{democracy}$_{t+1}$}} \\\\ \\cmidrule{2-3} \\cmidrule{5-6} \\cmidrule{8-9} \\cmidrule{11-12} \\cmidrule{14-15} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header3a <- paste ("& \\multicolumn{1}{c}{(1)} & \\multicolumn{1}{c}{(2)} & & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & & \\multicolumn{1}{c}{(5)} & \\multicolumn{1}{c}{(6)} & & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} \\\\ \\midrule \n")
Header3b <- paste ("& \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} & & \\multicolumn{1}{c}{(13)} & \\multicolumn{1}{c}{(14)} & & \\multicolumn{1}{c}{(15)} & \\multicolumn{1}{c}{(16)} & & \\multicolumn{1}{c}{(17)} & \\multicolumn{1}{c}{(18)} & & \\multicolumn{1}{c}{(19)} & \\multicolumn{1}{c}{(20)} \\\\ \\midrule \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 8
addtorow$pos[[5]] <- 8
addtorow$pos[[6]] <- 8
addtorow$command <- c (Header1a, Header2, Header3a
                       , Header1b, Header2, Header3b)
print (xtable (cbind (rows, parSE (coefOutcome11tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Examining potential mechanisms: Marginal effect of \\emph{growth}$_{t-1}$ on alternative outcomes"
               , label="T:outcomes")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)





### (4) Alternative specifications: Tables A19-A28 and Figures A12-A21

## (4.1) Table A19: Controlling for GDP/Head only
(coefSpecification01a <- cbind (
  c (sum.m100b$coef[1,1], rep (NA, 8+2), sum.m100b$coef[2,1], rep (NA, 2+4))
  , rep (NA, 18)
  , c (NA, sum.m101b$coef[1,1], rep (NA, 7+2), sum.m101b$coef[2,1], rep (NA, 2+4))
  , c (sum.m102b$coef[1:3,1], rep (NA, 6+2), sum.m102b$coef[4,1], rep (NA, 2), sum.m102b$coef[1,1], sum.m102b$coef[1,1], sum.m102b$coef[1,1]+sum.m102b$coef[3,1], sum.m102b$coef[1,1]+sum.m102b$coef[3,1])
  , c (sum.m103b$coef[1:7,1], rep (NA, 2+2), sum.m103b$coef[8,1], rep (NA, 2), sum.m103b$coef[1,1], sum.m103b$coef[1,1]+sum.m103b$coef[4,1], sum.m103b$coef[1,1]+sum.m103b$coef[3,1], sum.m103b$coef[1,1]+sum.m103b$coef[3,1]+sum.m103b$coef[4,1]+sum.m103b$coef[5,1])
  , c (sum.m103f$coef[1:7,1], rep (NA, 2+2), sum.m103f$coef[8:10,1], sum.m103f$coef[1,1], sum.m103f$coef[1,1]+sum.m103f$coef[4,1], sum.m103f$coef[1,1]+sum.m103f$coef[3,1], sum.m103f$coef[1,1]+sum.m103f$coef[3,1]+sum.m103f$coef[4,1]+sum.m103f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m110b$coef[1,1], rep (NA, 5), sum.m110b$coef[2,1], rep (NA, 1+2), sum.m110b$coef[3,1], rep (NA, 2+4))
  , c (sum.m111b$coef[c (1:2,4),1], rep (NA, 4), sum.m111b$coef[c (3,5),1], rep (NA, 2), sum.m111b$coef[6,1], rep (NA, 2), sum.m111b$coef[1,1], sum.m111b$coef[1,1]+sum.m111b$coef[5,1], NA, sum.m111b$coef[1,1]+sum.m111b$coef[4,1])
  , c (sum.m111f$coef[c (1:2,4),1], rep (NA, 4), sum.m111f$coef[c (3,5),1], rep (NA, 2), sum.m111f$coef[6:8,1], sum.m111f$coef[1,1], sum.m111f$coef[1,1]+sum.m111f$coef[5,1], NA, sum.m111f$coef[1,1]+sum.m111f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m105b$coef[1:7,1], rep (NA, 2+2), sum.m105b$coef[8,1], rep (NA, 2), sum.m105b$coef[1,1], sum.m105b$coef[1,1]+sum.m105b$coef[4,1], sum.m105b$coef[1,1]+sum.m105b$coef[3,1], sum.m105b$coef[1,1]+sum.m105b$coef[3,1]+sum.m105b$coef[4,1]+sum.m105b$coef[5,1])
  , c (sum.m113b$coef[c (1:2,4),1], rep (NA, 4), sum.m113b$coef[c (3,5),1], rep (NA, 2), sum.m113b$coef[6,1], rep (NA, 2), sum.m113b$coef[1,1], sum.m113b$coef[1,1]+sum.m113b$coef[5,1], NA, sum.m113b$coef[1,1]+sum.m113b$coef[4,1])
  , rep (NA, 18)
  , c (sum.m109b$coef[1:7,1], rep (NA, 2+2), sum.m109b$coef[8,1], rep (NA, 2), sum.m109b$coef[1,1], sum.m109b$coef[1,1]+sum.m109b$coef[4,1], sum.m109b$coef[1,1]+sum.m109b$coef[3,1], sum.m109b$coef[1,1]+sum.m109b$coef[3,1]+sum.m109b$coef[4,1]+sum.m109b$coef[5,1])
  , c (sum.m117b$coef[c (1:2,4),1], rep (NA, 4), sum.m117b$coef[c (3,5:8),1], rep (NA, 2), sum.m117b$coef[1,1], sum.m117b$coef[1,1]+sum.m117b$coef[5,1], NA, sum.m117b$coef[1,1]+sum.m117b$coef[4,1])))
(seSpecification01a <- cbind (
  c (sum.m100b$coef[1,2], rep (NA, 8+2), sum.m100b$coef[2,2], rep (NA, 2+4))
  , rep (NA, 18)
  , c (NA, sum.m101b$coef[1,2], rep (NA, 7+2), sum.m101b$coef[2,2], rep (NA, 2+4))
  , c (sum.m102b$coef[1:3,2], rep (NA, 6+2), sum.m102b$coef[4,2], rep (NA, 2)
       , sqrt (vcov (m102b)[1,1])
       , sqrt (vcov (m102b)[1,1])
       , sqrt (vcov (m102b)[1,1]+1^2*vcov (m102b)[3,3]+2*1*vcov (m102b)[1,3])
       , sqrt (vcov (m102b)[1,1]+1^2*vcov (m102b)[3,3]+2*1*vcov (m102b)[1,3]))
  , c (sum.m103b$coef[1:7,2], rep (NA, 2+2), sum.m103b$coef[8,2], rep (NA, 2)
       , sqrt (vcov (m103b)[1,1])
       , sqrt (vcov (m103b)[1,1]+1^2*vcov (m103b)[4,4]+2*1*vcov (m103b)[1,4])
       , sqrt (vcov (m103b)[1,1]+1^2*vcov (m103b)[3,3]+2*1*vcov (m103b)[1,3])
       , sqrt (vcov (m103b)[1,1]+1^2*vcov (m103b)[3,3]+1^2*vcov (m103b)[4,4]+1^2*1^2*vcov (m103b)[5,5]+2*1*vcov (m103b)[1,3]+2*1*vcov (m103b)[1,4]+2*1*1*vcov (m103b)[1,5]+2*1*1*vcov (m103b)[3,4]+2*1*1^2*vcov (m103b)[3,5]+2*1*1^2*vcov (m103b)[4,5]))
  , c (sum.m103f$coef[1:7,2], rep (NA, 2+2), sum.m103f$coef[8:10,2]
       , sqrt (vcov (m103f)[1,1])
       , sqrt (vcov (m103f)[1,1]+1^2*vcov (m103f)[4,4]+2*1*vcov (m103f)[1,4])
       , sqrt (vcov (m103f)[1,1]+1^2*vcov (m103f)[3,3]+2*1*vcov (m103f)[1,3])
       , sqrt (vcov (m103f)[1,1]+1^2*vcov (m103f)[3,3]+1^2*vcov (m103f)[4,4]+1^2*1^2*vcov (m103f)[5,5]+2*1*vcov (m103f)[1,3]+2*1*vcov (m103f)[1,4]+2*1*1*vcov (m103f)[1,5]+2*1*1*vcov (m103f)[3,4]+2*1*1^2*vcov (m103f)[3,5]+2*1*1^2*vcov (m103f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m110b$coef[1,2], rep (NA, 5), sum.m110b$coef[2,2], rep (NA, 1+2), sum.m110b$coef[3,2], rep (NA, 2+4))
  , c (sum.m111b$coef[c (1:2,4),2], rep (NA, 4), sum.m111b$coef[c (3,5),2], rep (NA, 2), sum.m111b$coef[6,2], rep (NA, 2)
       , sqrt (vcov (m111b)[1,1])
       , sqrt (vcov (m111b)[1,1]+1^2*vcov (m111b)[5,5]+2*1*vcov (m111b)[1,5])
       , NA
       , sqrt (vcov (m111b)[1,1]+1^2*vcov (m111b)[4,4]+2*1*vcov (m111b)[1,4]))
  , c (sum.m111f$coef[c (1:2,4),2], rep (NA, 4), sum.m111f$coef[c (3,5),2], rep (NA, 2), sum.m111f$coef[6:8,2]
       , sqrt (vcov (m111f)[1,1])
       , sqrt (vcov (m111f)[1,1]+1^2*vcov (m111f)[5,5]+2*1*vcov (m111f)[1,5])
       , NA
       , sqrt (vcov (m111f)[1,1]+1^2*vcov (m111f)[4,4]+2*1*vcov (m111f)[1,4]))
  , rep (NA, 18)
  , c (sum.m105b$coef[1:7,2], rep (NA, 2+2), sum.m105b$coef[8,2], rep (NA, 2)
       , sqrt (vcov (m105b)[1,1])
       , sqrt (vcov (m105b)[1,1]+1^2*vcov (m105b)[4,4]+2*1*vcov (m105b)[1,4])
       , sqrt (vcov (m105b)[1,1]+1^2*vcov (m105b)[3,3]+2*1*vcov (m105b)[1,3])
       , sqrt (vcov (m105b)[1,1]+1^2*vcov (m105b)[3,3]+1^2*vcov (m105b)[4,4]+1^2*1^2*vcov (m105b)[5,5]+2*1*vcov (m105b)[1,3]+2*1*vcov (m105b)[1,4]+2*1*1*vcov (m105b)[1,5]+2*1*1*vcov (m105b)[3,4]+2*1*1^2*vcov (m105b)[3,5]+2*1*1^2*vcov (m105b)[4,5]))
  , c (sum.m113b$coef[c (1:2,4),2], rep (NA, 4), sum.m113b$coef[c (3,5),2], rep (NA, 2), sum.m113b$coef[6,2], rep (NA, 2)
       , sqrt (vcov (m113b)[1,1])
       , sqrt (vcov (m113b)[1,1]+1^2*vcov (m113b)[5,5]+2*1*vcov (m113b)[1,5])
       , NA
       , sqrt (vcov (m113b)[1,1]+1^2*vcov (m113b)[4,4]+2*1*vcov (m113b)[1,4]))
  , rep (NA, 18)
  , c (sum.m109b$coef[1:7,2], rep (NA, 2+2), sum.m109b$coef[8,2], rep (NA, 2)
       , sqrt (vcov (m109b)[1,1])
       , sqrt (vcov (m109b)[1,1]+1^2*vcov (m109b)[4,4]+2*1*vcov (m109b)[1,4])
       , sqrt (vcov (m109b)[1,1]+1^2*vcov (m109b)[3,3]+2*1*vcov (m109b)[1,3])
       , sqrt (vcov (m109b)[1,1]+1^2*vcov (m109b)[3,3]+1^2*vcov (m109b)[4,4]+1^2*1^2*vcov (m109b)[5,5]+2*1*vcov (m109b)[1,3]+2*1*vcov (m109b)[1,4]+2*1*1*vcov (m109b)[1,5]+2*1*1*vcov (m109b)[3,4]+2*1*1^2*vcov (m109b)[3,5]+2*1*1^2*vcov (m109b)[4,5]))
  , c (sum.m117b$coef[c (1:2,4),2], rep (NA, 4), sum.m117b$coef[c (3,5:8),2], rep (NA, 2)
       , sqrt (vcov (m117b)[1,1])
       , sqrt (vcov (m117b)[1,1]+1^2*vcov (m117b)[5,5]+2*1*vcov (m117b)[1,5])
       , NA
       , sqrt (vcov (m117b)[1,1]+1^2*vcov (m117b)[4,4]+2*1*vcov (m117b)[1,4]))))

odd <- seq (1, nrow (coefSpecification01a)*2, by=2); even <- seq (2, nrow (coefSpecification01a)*2, by=2)
(coefSpecification01tab <- data.frame (rbind (coefSpecification01a, seSpecification01a))) ## warnings reported. Don't worry
rownames (coefSpecification01tab) <- c (odd, even)
coefSpecification01tab <- coefSpecification01tab[order (as.numeric (rownames (coefSpecification01tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m100b$N, length (unique (sum.m100b$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m100b$fe$year.f)))
  , c (sum.m101b$N, length (unique (sum.m101b$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m101b$fe$year.f)))
  , c (sum.m102b$N, length (unique (sum.m102b$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m102b$fe$year.f)))
  , c (sum.m103b$N, length (unique (sum.m103b$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m103b$fe$year.f)))
  , c (sum.m103f$N, length (unique (sum.m103f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m103f$fe$year.f)))
  , c (sum.m110b$N, length (unique (sum.m110b$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m110b$fe$year.f)))
  , c (sum.m111b$N, length (unique (sum.m111b$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m111b$fe$year.f)))
  , c (sum.m111f$N, length (unique (sum.m111f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m111f$fe$year.f)))
  , c (sum.m105b$N, length (unique (sum.m105b$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m105b$fe$year.f)))
  , c (sum.m113b$N, length (unique (sum.m113b$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m113b$fe$year.f)))
  , c (sum.m109b$N, length (unique (sum.m109b$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m109b$fe$year.f)))
  , c (sum.m117b$N, length (unique (sum.m117b$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m117b$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefSpecification01tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Adding controls (1): \\emph{GDP per capita}$_{t-1}$ (log)"
               , label="T:rSpecificationGDP")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (4.1.2) Figure A12

# (4.1.2.1) Marginal effect of growth (t-1) on Pr (breakdown t):

# creating the dataset for the plots
dPlotSpecification01g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotSpecification01g) <- "dataset"
dPlotSpecification01g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotSpecification01g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotSpecification01g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotSpecification01g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotSpecification01g$estimate <- c (coefSpecification01tab[c (29, 33, 31, 35),5], coefSpecification01tab[c (29, 33, 31, 35),9]
                                     , coefSpecification01tab[c (29, 33, 31, 35),6], coefSpecification01tab[c (29, 33, 31, 35),10]
                                     , coefSpecification01tab[c (29, 33, 31, 35),12], coefSpecification01tab[c (29, 33, 31, 35),13]
                                     , coefSpecification01tab[c (29, 33, 31, 35),15], coefSpecification01tab[c (29, 33, 31, 35),16])
dPlotSpecification01g$se <- c (coefSpecification01tab[c (29, 33, 31, 35)+1,5], coefSpecification01tab[c (29, 33, 31, 35)+1,9]
                               , coefSpecification01tab[c (29, 33, 31, 35)+1,6], coefSpecification01tab[c (29, 33, 31, 35)+1,10]
                               , coefSpecification01tab[c (29, 33, 31, 35)+1,12], coefSpecification01tab[c (29, 33, 31, 35)+1,13]
                               , coefSpecification01tab[c (29, 33, 31, 35)+1,15], coefSpecification01tab[c (29, 33, 31, 35)+1,16])
dPlotSpecification01g$ciLow <- with (dPlotSpecification01g, estimate + se*qt (0.025, df=n))
dPlotSpecification01g$ciHigh <- with (dPlotSpecification01g, estimate + se*qt (0.975, df=n))
dPlotSpecification01g <- dPlotSpecification01g[!is.na (dPlotSpecification01g$estimate),]
dPlotSpecification01g$effect <- factor (dPlotSpecification01g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (4.1.2.2) Marginal effect of election (t) on Pr (breakdown t):
dPlotSpecification01el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotSpecification01el) <- "dataset"
dPlotSpecification01el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotSpecification01el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotSpecification01el$growth <- rep (seq (min (maddMain$madddGDPHead_lag), max (maddMain$madddGDPHead_lag), length.out=m), 3)
dPlotSpecification01el$estimate <- with (dPlotSpecification01el, ifelse (
  elType=="actual elections\n(closed)", sum.m103b$coef[2,1]+sum.m103b$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m103b$coef[2,1]+sum.m103b$coef[7,1]+(sum.m103b$coef[3,1]+sum.m103b$coef[5,1])*growth, sum.m111a$coef[2,1]+sum.m111a$coef[4,1]*growth)))
dPlotSpecification01el$se <- with (dPlotSpecification01el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m103b)[2,2] + (growth^2)*vcov (m103b)[3,3] + (2*growth)*vcov (m103b)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m103b)[2,2] + (growth^2)*vcov (m103b)[3,3] + (1^2)*vcov (m103b)[7,7] + (growth^2)*(1^2)*vcov (m103b)[5,5] + (2*growth)*vcov (m103b)[2,3] + (2*1)*vcov (m103b)[2,7] + (2*growth*1)*vcov (m103b)[2,5] + (2*growth*1)*vcov (m103b)[3,7] + (2*1*growth^2)*vcov (m103b)[3,5] + (2*growth*1^2)*vcov (m103b)[7,5]), sqrt (vcov (m111a)[2,2] + (growth^2)*vcov (m111a)[4,4] + (2*growth)*vcov (m111a)[2,4]))))
dPlotSpecification01el$ciLow <- with (dPlotSpecification01el, estimate + se*qt (0.025, df=n))
dPlotSpecification01el$ciHigh <- with (dPlotSpecification01el, estimate + se*qt (0.975, df=n))
dPlotSpecification01el <- dPlotSpecification01el[abs (dPlotSpecification01el$growth) <= h.lim,]

# (4.1.2.3) Drawing the plots

# Specification results for growth|elections (with and without controls)
(pEffectSpecification01 <- ggplot (dPlotSpecification01g[dPlotSpecification01g$elType=="competitive\n& executive",]
                                   , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Specification vs. Placebos for growth|elections
(pEffectSpecification02 <- ggplot (dPlotSpecification01g[dPlotSpecification01g$controls=="no controls",]
                                   , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthSpecification <- ggplot (maddMain[abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Specification results for elections|growth
(pEffectSpecification03 <- ggplot (dPlotSpecification01el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthSpecification), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# (4.1.2.4) Exporting the plots
png ("Figures/fig_rSpecificationGDP01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecification01
dev.off ()
png ("Figures/fig_rSpecificationGDP02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecification02
dev.off ()
png ("Figures/fig_rSpecificationGDP03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectSpecification03
dev.off ()


## (4.2) Table A20: No controls, Oil and gas/Head sample
(coefSpecification02a <- cbind (
  c (sum.m100f2$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m101f2$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m102f2$coef[1:3,1], rep (NA, 6+5), sum.m102f2$coef[1,1], sum.m102f2$coef[1,1], sum.m102f2$coef[1,1]+sum.m102f2$coef[3,1], sum.m102f2$coef[1,1]+sum.m102f2$coef[3,1])
  , c (sum.m103f2$coef[1:7,1], rep (NA, 2+5), sum.m103f2$coef[1,1], sum.m103f2$coef[1,1]+sum.m103f2$coef[4,1], sum.m103f2$coef[1,1]+sum.m103f2$coef[3,1], sum.m103f2$coef[1,1]+sum.m103f2$coef[3,1]+sum.m103f2$coef[4,1]+sum.m103f2$coef[5,1])
  , c (sum.m103f$coef[1:7,1], rep (NA, 2+2), sum.m103f$coef[8:10,1], sum.m103f$coef[1,1], sum.m103f$coef[1,1]+sum.m103f$coef[4,1], sum.m103f$coef[1,1]+sum.m103f$coef[3,1], sum.m103f$coef[1,1]+sum.m103f$coef[3,1]+sum.m103f$coef[4,1]+sum.m103f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m110f2$coef[1,1], rep (NA, 5), sum.m110f2$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m111f2$coef[c (1:2,4),1], rep (NA, 4), sum.m111f2$coef[c (3,5),1], rep (NA, 5), sum.m111f2$coef[1,1], sum.m111f2$coef[1,1]+sum.m111f2$coef[5,1], NA, sum.m111f2$coef[1,1]+sum.m111f2$coef[4,1])
  , c (sum.m111f$coef[c (1:2,4),1], rep (NA, 4), sum.m111f$coef[c (3,5),1], rep (NA, 2), sum.m111f$coef[6:8,1], sum.m111f$coef[1,1], sum.m111f$coef[1,1]+sum.m111f$coef[5,1], NA, sum.m111f$coef[1,1]+sum.m111f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m105f2$coef[1:7,1], rep (NA, 2+5), sum.m105f2$coef[1,1], sum.m105f2$coef[1,1]+sum.m105f2$coef[4,1], sum.m105f2$coef[1,1]+sum.m105f2$coef[3,1], sum.m105f2$coef[1,1]+sum.m105f2$coef[3,1]+sum.m105f2$coef[4,1]+sum.m105f2$coef[5,1])
  , c (sum.m113f2$coef[c (1:2,4),1], rep (NA, 4), sum.m113f2$coef[c (3,5),1], rep (NA, 5), sum.m113f2$coef[1,1], sum.m113f2$coef[1,1]+sum.m113f2$coef[5,1], NA, sum.m113f2$coef[1,1]+sum.m113f2$coef[4,1])
  , rep (NA, 18)
  , c (sum.m109f2$coef[1:7,1], rep (NA, 2+5), sum.m109f2$coef[1,1], sum.m109f2$coef[1,1]+sum.m109f2$coef[4,1], sum.m109f2$coef[1,1]+sum.m109f2$coef[3,1], sum.m109f2$coef[1,1]+sum.m109f2$coef[3,1]+sum.m109f2$coef[4,1]+sum.m109f2$coef[5,1])
  , c (sum.m117f2$coef[c (1:2,4),1], rep (NA, 4), sum.m117f2$coef[c (3,5:7),1], rep (NA, 3), sum.m117f2$coef[1,1], sum.m117f2$coef[1,1]+sum.m117f2$coef[5,1], NA, sum.m117f2$coef[1,1]+sum.m117f2$coef[4,1])))
(seSpecification02a <- cbind (
  c (sum.m100f2$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m101f2$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m102f2$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m102f2)[1,1])
       , sqrt (vcov (m102f2)[1,1])
       , sqrt (vcov (m102f2)[1,1]+1^2*vcov (m102f2)[3,3]+2*1*vcov (m102f2)[1,3])
       , sqrt (vcov (m102f2)[1,1]+1^2*vcov (m102f2)[3,3]+2*1*vcov (m102f2)[1,3]))
  , c (sum.m103f2$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m103f2)[1,1])
       , sqrt (vcov (m103f2)[1,1]+1^2*vcov (m103f2)[4,4]+2*1*vcov (m103f2)[1,4])
       , sqrt (vcov (m103f2)[1,1]+1^2*vcov (m103f2)[3,3]+2*1*vcov (m103f2)[1,3])
       , sqrt (vcov (m103f2)[1,1]+1^2*vcov (m103f2)[3,3]+1^2*vcov (m103f2)[4,4]+1^2*1^2*vcov (m103f2)[5,5]+2*1*vcov (m103f2)[1,3]+2*1*vcov (m103f2)[1,4]+2*1*1*vcov (m103f2)[1,5]+2*1*1*vcov (m103f2)[3,4]+2*1*1^2*vcov (m103f2)[3,5]+2*1*1^2*vcov (m103f2)[4,5]))
  , c (sum.m103f$coef[1:7,2], rep (NA, 2+2), sum.m103f$coef[8:10,2]
       , sqrt (vcov (m103f)[1,1])
       , sqrt (vcov (m103f)[1,1]+1^2*vcov (m103f)[4,4]+2*1*vcov (m103f)[1,4])
       , sqrt (vcov (m103f)[1,1]+1^2*vcov (m103f)[3,3]+2*1*vcov (m103f)[1,3])
       , sqrt (vcov (m103f)[1,1]+1^2*vcov (m103f)[3,3]+1^2*vcov (m103f)[4,4]+1^2*1^2*vcov (m103f)[5,5]+2*1*vcov (m103f)[1,3]+2*1*vcov (m103f)[1,4]+2*1*1*vcov (m103f)[1,5]+2*1*1*vcov (m103f)[3,4]+2*1*1^2*vcov (m103f)[3,5]+2*1*1^2*vcov (m103f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m110f2$coef[1,2], rep (NA, 5), sum.m110f2$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m111f2$coef[c (1:2,4),2], rep (NA, 4), sum.m111f2$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m111f2)[1,1])
       , sqrt (vcov (m111f2)[1,1]+1^2*vcov (m111f2)[5,5]+2*1*vcov (m111f2)[1,5])
       , NA
       , sqrt (vcov (m111f2)[1,1]+1^2*vcov (m111f2)[4,4]+2*1*vcov (m111f2)[1,4]))
  , c (sum.m111f$coef[c (1:2,4),2], rep (NA, 4), sum.m111f$coef[c (3,5),2], rep (NA, 2), sum.m111f$coef[6:8,2]
       , sqrt (vcov (m111f)[1,1])
       , sqrt (vcov (m111f)[1,1]+1^2*vcov (m111f)[5,5]+2*1*vcov (m111f)[1,5])
       , NA
       , sqrt (vcov (m111f)[1,1]+1^2*vcov (m111f)[4,4]+2*1*vcov (m111f)[1,4]))
  , rep (NA, 18)
  , c (sum.m105f2$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m105f2)[1,1])
       , sqrt (vcov (m105f2)[1,1]+1^2*vcov (m105f2)[4,4]+2*1*vcov (m105f2)[1,4])
       , sqrt (vcov (m105f2)[1,1]+1^2*vcov (m105f2)[3,3]+2*1*vcov (m105f2)[1,3])
       , sqrt (vcov (m105f2)[1,1]+1^2*vcov (m105f2)[3,3]+1^2*vcov (m105f2)[4,4]+1^2*1^2*vcov (m105f2)[5,5]+2*1*vcov (m105f2)[1,3]+2*1*vcov (m105f2)[1,4]+2*1*1*vcov (m105f2)[1,5]+2*1*1*vcov (m105f2)[3,4]+2*1*1^2*vcov (m105f2)[3,5]+2*1*1^2*vcov (m105f2)[4,5]))
  , c (sum.m113f2$coef[c (1:2,4),2], rep (NA, 4), sum.m113f2$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m113f2)[1,1])
       , sqrt (vcov (m113f2)[1,1]+1^2*vcov (m113f2)[5,5]+2*1*vcov (m113f2)[1,5])
       , NA
       , sqrt (vcov (m113f2)[1,1]+1^2*vcov (m113f2)[4,4]+2*1*vcov (m113f2)[1,4]))
  , rep (NA, 18)
  , c (sum.m109f2$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m109f2)[1,1])
       , sqrt (vcov (m109f2)[1,1]+1^2*vcov (m109f2)[4,4]+2*1*vcov (m109f2)[1,4])
       , sqrt (vcov (m109f2)[1,1]+1^2*vcov (m109f2)[3,3]+2*1*vcov (m109f2)[1,3])
       , sqrt (vcov (m109f2)[1,1]+1^2*vcov (m109f2)[3,3]+1^2*vcov (m109f2)[4,4]+1^2*1^2*vcov (m109f2)[5,5]+2*1*vcov (m109f2)[1,3]+2*1*vcov (m109f2)[1,4]+2*1*1*vcov (m109f2)[1,5]+2*1*1*vcov (m109f2)[3,4]+2*1*1^2*vcov (m109f2)[3,5]+2*1*1^2*vcov (m109f2)[4,5]))
  , c (sum.m117f2$coef[c (1:2,4),2], rep (NA, 4), sum.m117f2$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m117f2)[1,1])
       , sqrt (vcov (m117f2)[1,1]+1^2*vcov (m117f2)[5,5]+2*1*vcov (m117f2)[1,5])
       , NA
       , sqrt (vcov (m117f2)[1,1]+1^2*vcov (m117f2)[4,4]+2*1*vcov (m117f2)[1,4]))))

odd <- seq (1, nrow (coefSpecification02a)*2, by=2); even <- seq (2, nrow (coefSpecification02a)*2, by=2)
(coefSpecification02tab <- data.frame (rbind (coefSpecification02a, seSpecification02a))) ## warnings reported. Don't worry
rownames (coefSpecification02tab) <- c (odd, even)
coefSpecification02tab <- coefSpecification02tab[order (as.numeric (rownames (coefSpecification02tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m100f2$N, length (unique (sum.m100f2$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m100f2$fe$year.f)))
  , c (sum.m101f2$N, length (unique (sum.m101f2$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m101f2$fe$year.f)))
  , c (sum.m102f2$N, length (unique (sum.m102f2$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m102f2$fe$year.f)))
  , c (sum.m103f2$N, length (unique (sum.m103f2$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m103f2$fe$year.f)))
  , c (sum.m103f$N, length (unique (sum.m103f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m103f$fe$year.f)))
  , c (sum.m110f2$N, length (unique (sum.m110f2$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m110f2$fe$year.f)))
  , c (sum.m111f2$N, length (unique (sum.m111f2$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m111f2$fe$year.f)))
  , c (sum.m111f$N, length (unique (sum.m111f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m111f$fe$year.f)))
  , c (sum.m105f2$N, length (unique (sum.m105f2$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m105f2$fe$year.f)))
  , c (sum.m113f2$N, length (unique (sum.m113f2$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m113f2$fe$year.f)))
  , c (sum.m109f2$N, length (unique (sum.m109f2$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m109f2$fe$year.f)))
  , c (sum.m117f2$N, length (unique (sum.m117f2$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m117f2$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefSpecification02tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Adding controls (2): \\emph{oil and gas per capita}$_{t-1}$ sample"
               , label="T:rSpecificationOilSample")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (4.2.2) Figure A13

# (4.2.2.1) Marginal effect of growth (t-1) on Pr (breakdown t):

# creating the dataset for the plots
dPlotSpecification02g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotSpecification02g) <- "dataset"
dPlotSpecification02g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotSpecification02g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotSpecification02g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotSpecification02g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotSpecification02g$estimate <- c (coefSpecification02tab[c (29, 33, 31, 35),5], coefSpecification02tab[c (29, 33, 31, 35),9]
                                     , coefSpecification02tab[c (29, 33, 31, 35),6], coefSpecification02tab[c (29, 33, 31, 35),10]
                                     , coefSpecification02tab[c (29, 33, 31, 35),12], coefSpecification02tab[c (29, 33, 31, 35),13]
                                     , coefSpecification02tab[c (29, 33, 31, 35),15], coefSpecification02tab[c (29, 33, 31, 35),16])
dPlotSpecification02g$se <- c (coefSpecification02tab[c (29, 33, 31, 35)+1,5], coefSpecification02tab[c (29, 33, 31, 35)+1,9]
                               , coefSpecification02tab[c (29, 33, 31, 35)+1,6], coefSpecification02tab[c (29, 33, 31, 35)+1,10]
                               , coefSpecification02tab[c (29, 33, 31, 35)+1,12], coefSpecification02tab[c (29, 33, 31, 35)+1,13]
                               , coefSpecification02tab[c (29, 33, 31, 35)+1,15], coefSpecification02tab[c (29, 33, 31, 35)+1,16])
dPlotSpecification02g$ciLow <- with (dPlotSpecification02g, estimate + se*qt (0.025, df=n))
dPlotSpecification02g$ciHigh <- with (dPlotSpecification02g, estimate + se*qt (0.975, df=n))
dPlotSpecification02g <- dPlotSpecification02g[!is.na (dPlotSpecification02g$estimate),]
dPlotSpecification02g$effect <- factor (dPlotSpecification02g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (4.2.2.2) Marginal effect of election (t) on Pr (breakdown t):
dPlotSpecification02el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotSpecification02el) <- "dataset"
dPlotSpecification02el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotSpecification02el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotSpecification02el$growth <- rep (seq (min (maddMain$madddGDPHead_lag), max (maddMain$madddGDPHead_lag), length.out=m), 3)
dPlotSpecification02el$estimate <- with (dPlotSpecification02el, ifelse (
  elType=="actual elections\n(closed)", sum.m103f2$coef[2,1]+sum.m103f2$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m103f2$coef[2,1]+sum.m103f2$coef[7,1]+(sum.m103f2$coef[3,1]+sum.m103f2$coef[5,1])*growth, sum.m111f2$coef[2,1]+sum.m111f2$coef[4,1]*growth)))
dPlotSpecification02el$se <- with (dPlotSpecification02el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m103f2)[2,2] + (growth^2)*vcov (m103f2)[3,3] + (2*growth)*vcov (m103f2)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m103f2)[2,2] + (growth^2)*vcov (m103f2)[3,3] + (1^2)*vcov (m103f2)[7,7] + (growth^2)*(1^2)*vcov (m103f2)[5,5] + (2*growth)*vcov (m103f2)[2,3] + (2*1)*vcov (m103f2)[2,7] + (2*growth*1)*vcov (m103f2)[2,5] + (2*growth*1)*vcov (m103f2)[3,7] + (2*1*growth^2)*vcov (m103f2)[3,5] + (2*growth*1^2)*vcov (m103f2)[7,5]), sqrt (vcov (m111f2)[2,2] + (growth^2)*vcov (m111f2)[4,4] + (2*growth)*vcov (m111f2)[2,4]))))
dPlotSpecification02el$ciLow <- with (dPlotSpecification02el, estimate + se*qt (0.025, df=n))
dPlotSpecification02el$ciHigh <- with (dPlotSpecification02el, estimate + se*qt (0.975, df=n))
dPlotSpecification02el <- dPlotSpecification02el[abs (dPlotSpecification02el$growth) <= h.lim,]

# (4.2.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectSpecification01 <- ggplot (dPlotSpecification02g[dPlotSpecification02g$elType=="competitive\n& executive",]
                                   , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectSpecification02 <- ggplot (dPlotSpecification02g[dPlotSpecification02g$controls=="no controls",]
                                   , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthSpecification <- ggplot (maddMain[abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectSpecification03 <- ggplot (dPlotSpecification02el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthSpecification), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# (4.2.2.4) Exporting the plots
png ("Figures/fig_rSpecificationOilSample01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecification01
dev.off ()
png ("Figures/fig_rSpecificationOilSample02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecification02
dev.off ()
png ("Figures/fig_rSpecificationOilSample03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectSpecification03
dev.off ()


## (4.3) Table A21: Controlling for Oil and gas/Head only
(coefSpecification03a <- cbind (
  c (sum.m100c$coef[1,1], rep (NA, 8+3), sum.m100c$coef[2,1], rep (NA, 1+4))
  , rep (NA, 18)
  , c (NA, sum.m101c$coef[1,1], rep (NA, 7+3), sum.m101c$coef[2,1], rep (NA, 1+4))
  , c (sum.m102c$coef[1:3,1], rep (NA, 6+3), sum.m102c$coef[4,1], rep (NA, 1), sum.m102c$coef[1,1], sum.m102c$coef[1,1], sum.m102c$coef[1,1]+sum.m102c$coef[3,1], sum.m102c$coef[1,1]+sum.m102c$coef[3,1])
  , c (sum.m103c$coef[1:7,1], rep (NA, 2+3), sum.m103c$coef[8,1], rep (NA, 1), sum.m103c$coef[1,1], sum.m103c$coef[1,1]+sum.m103c$coef[4,1], sum.m103c$coef[1,1]+sum.m103c$coef[3,1], sum.m103c$coef[1,1]+sum.m103c$coef[3,1]+sum.m103c$coef[4,1]+sum.m103c$coef[5,1])
  , c (sum.m103f$coef[1:7,1], rep (NA, 2+2), sum.m103f$coef[8:10,1], sum.m103f$coef[1,1], sum.m103f$coef[1,1]+sum.m103f$coef[4,1], sum.m103f$coef[1,1]+sum.m103f$coef[3,1], sum.m103f$coef[1,1]+sum.m103f$coef[3,1]+sum.m103f$coef[4,1]+sum.m103f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m110c$coef[1,1], rep (NA, 5), sum.m110c$coef[2,1], rep (NA, 1+3), sum.m110c$coef[3,1], rep (NA, 1+4))
  , c (sum.m111c$coef[c (1:2,4),1], rep (NA, 4), sum.m111c$coef[c (3,5),1], rep (NA, 2+1), sum.m111c$coef[6,1], rep (NA, 1), sum.m111c$coef[1,1], sum.m111c$coef[1,1]+sum.m111c$coef[5,1], NA, sum.m111c$coef[1,1]+sum.m111c$coef[4,1])
  , c (sum.m111f$coef[c (1:2,4),1], rep (NA, 4), sum.m111f$coef[c (3,5),1], rep (NA, 2), sum.m111f$coef[6:8,1], sum.m111f$coef[1,1], sum.m111f$coef[1,1]+sum.m111f$coef[5,1], NA, sum.m111f$coef[1,1]+sum.m111f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m105c$coef[1:7,1], rep (NA, 2+3), sum.m105c$coef[8,1], rep (NA, 1), sum.m105c$coef[1,1], sum.m105c$coef[1,1]+sum.m105c$coef[4,1], sum.m105c$coef[1,1]+sum.m105c$coef[3,1], sum.m105c$coef[1,1]+sum.m105c$coef[3,1]+sum.m105c$coef[4,1]+sum.m105c$coef[5,1])
  , c (sum.m113c$coef[c (1:2,4),1], rep (NA, 4), sum.m113c$coef[c (3,5),1], rep (NA, 2+1), sum.m113c$coef[6,1], rep (NA, 1), sum.m113c$coef[1,1], sum.m113c$coef[1,1]+sum.m113c$coef[5,1], NA, sum.m113c$coef[1,1]+sum.m113c$coef[4,1])
  , rep (NA, 18)
  , c (sum.m109c$coef[1:7,1], rep (NA, 2+3), sum.m109c$coef[8,1], rep (NA, 1), sum.m109c$coef[1,1], sum.m109c$coef[1,1]+sum.m109c$coef[4,1], sum.m109c$coef[1,1]+sum.m109c$coef[3,1], sum.m109c$coef[1,1]+sum.m109c$coef[3,1]+sum.m109c$coef[4,1]+sum.m109c$coef[5,1])
  , c (sum.m117c$coef[c (1:2,4),1], rep (NA, 4), sum.m117c$coef[c (3,5:7),1], rep (NA, 1), sum.m117c$coef[8,1], rep (NA, 1), sum.m117c$coef[1,1], sum.m117c$coef[1,1]+sum.m117c$coef[5,1], NA, sum.m117c$coef[1,1]+sum.m117c$coef[4,1])))
(seSpecification03a <- cbind (
  c (sum.m100c$coef[1,2], rep (NA, 8+3), sum.m100c$coef[2,2], rep (NA, 1+4))
  , rep (NA, 18)
  , c (NA, sum.m101c$coef[1,2], rep (NA, 7+3), sum.m101c$coef[2,2], rep (NA, 1+4))
  , c (sum.m102c$coef[1:3,2], rep (NA, 6+3), sum.m102c$coef[4,2], rep (NA, 1)
       , sqrt (vcov (m102c)[1,1])
       , sqrt (vcov (m102c)[1,1])
       , sqrt (vcov (m102c)[1,1]+1^2*vcov (m102c)[3,3]+2*1*vcov (m102c)[1,3])
       , sqrt (vcov (m102c)[1,1]+1^2*vcov (m102c)[3,3]+2*1*vcov (m102c)[1,3]))
  , c (sum.m103c$coef[1:7,2], rep (NA, 2+3), sum.m103c$coef[8,2], rep (NA, 1)
       , sqrt (vcov (m103c)[1,1])
       , sqrt (vcov (m103c)[1,1]+1^2*vcov (m103c)[4,4]+2*1*vcov (m103c)[1,4])
       , sqrt (vcov (m103c)[1,1]+1^2*vcov (m103c)[3,3]+2*1*vcov (m103c)[1,3])
       , sqrt (vcov (m103c)[1,1]+1^2*vcov (m103c)[3,3]+1^2*vcov (m103c)[4,4]+1^2*1^2*vcov (m103c)[5,5]+2*1*vcov (m103c)[1,3]+2*1*vcov (m103c)[1,4]+2*1*1*vcov (m103c)[1,5]+2*1*1*vcov (m103c)[3,4]+2*1*1^2*vcov (m103c)[3,5]+2*1*1^2*vcov (m103c)[4,5]))
  , c (sum.m103f$coef[1:7,2], rep (NA, 2+2), sum.m103f$coef[8:10,2]
       , sqrt (vcov (m103f)[1,1])
       , sqrt (vcov (m103f)[1,1]+1^2*vcov (m103f)[4,4]+2*1*vcov (m103f)[1,4])
       , sqrt (vcov (m103f)[1,1]+1^2*vcov (m103f)[3,3]+2*1*vcov (m103f)[1,3])
       , sqrt (vcov (m103f)[1,1]+1^2*vcov (m103f)[3,3]+1^2*vcov (m103f)[4,4]+1^2*1^2*vcov (m103f)[5,5]+2*1*vcov (m103f)[1,3]+2*1*vcov (m103f)[1,4]+2*1*1*vcov (m103f)[1,5]+2*1*1*vcov (m103f)[3,4]+2*1*1^2*vcov (m103f)[3,5]+2*1*1^2*vcov (m103f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m110c$coef[1,2], rep (NA, 5), sum.m110c$coef[2,2], rep (NA, 1+3), sum.m110c$coef[3,2], rep (NA, 1+4))
  , c (sum.m111c$coef[c (1:2,4),2], rep (NA, 4), sum.m111c$coef[c (3,5),2], rep (NA, 2+1), sum.m111c$coef[6,2], rep (NA, 1)
       , sqrt (vcov (m111c)[1,1])
       , sqrt (vcov (m111c)[1,1]+1^2*vcov (m111c)[5,5]+2*1*vcov (m111c)[1,5])
       , NA
       , sqrt (vcov (m111c)[1,1]+1^2*vcov (m111c)[4,4]+2*1*vcov (m111c)[1,4]))
  , c (sum.m111f$coef[c (1:2,4),2], rep (NA, 4), sum.m111f$coef[c (3,5),2], rep (NA, 2), sum.m111f$coef[6:8,2]
       , sqrt (vcov (m111f)[1,1])
       , sqrt (vcov (m111f)[1,1]+1^2*vcov (m111f)[5,5]+2*1*vcov (m111f)[1,5])
       , NA
       , sqrt (vcov (m111f)[1,1]+1^2*vcov (m111f)[4,4]+2*1*vcov (m111f)[1,4]))
  , rep (NA, 18)
  , c (sum.m105c$coef[1:7,2], rep (NA, 2+3), sum.m105c$coef[8,2], rep (NA, 1)
       , sqrt (vcov (m105c)[1,1])
       , sqrt (vcov (m105c)[1,1]+1^2*vcov (m105c)[4,4]+2*1*vcov (m105c)[1,4])
       , sqrt (vcov (m105c)[1,1]+1^2*vcov (m105c)[3,3]+2*1*vcov (m105c)[1,3])
       , sqrt (vcov (m105c)[1,1]+1^2*vcov (m105c)[3,3]+1^2*vcov (m105c)[4,4]+1^2*1^2*vcov (m105c)[5,5]+2*1*vcov (m105c)[1,3]+2*1*vcov (m105c)[1,4]+2*1*1*vcov (m105c)[1,5]+2*1*1*vcov (m105c)[3,4]+2*1*1^2*vcov (m105c)[3,5]+2*1*1^2*vcov (m105c)[4,5]))
  , c (sum.m113c$coef[c (1:2,4),2], rep (NA, 4), sum.m113c$coef[c (3,5),2], rep (NA, 2+1), sum.m113c$coef[6,2], rep (NA, 1)
       , sqrt (vcov (m113c)[1,1])
       , sqrt (vcov (m113c)[1,1]+1^2*vcov (m113c)[5,5]+2*1*vcov (m113c)[1,5])
       , NA
       , sqrt (vcov (m113c)[1,1]+1^2*vcov (m113c)[4,4]+2*1*vcov (m113c)[1,4]))
  , rep (NA, 18)
  , c (sum.m109c$coef[1:7,2], rep (NA, 2+3), sum.m109c$coef[8,2], rep (NA, 1)
       , sqrt (vcov (m109c)[1,1])
       , sqrt (vcov (m109c)[1,1]+1^2*vcov (m109c)[4,4]+2*1*vcov (m109c)[1,4])
       , sqrt (vcov (m109c)[1,1]+1^2*vcov (m109c)[3,3]+2*1*vcov (m109c)[1,3])
       , sqrt (vcov (m109c)[1,1]+1^2*vcov (m109c)[3,3]+1^2*vcov (m109c)[4,4]+1^2*1^2*vcov (m109c)[5,5]+2*1*vcov (m109c)[1,3]+2*1*vcov (m109c)[1,4]+2*1*1*vcov (m109c)[1,5]+2*1*1*vcov (m109c)[3,4]+2*1*1^2*vcov (m109c)[3,5]+2*1*1^2*vcov (m109c)[4,5]))
  , c (sum.m117c$coef[c (1:2,4),2], rep (NA, 4), sum.m117c$coef[c (3,5:7),2], rep (NA, 1), sum.m117c$coef[8,2], rep (NA, 1)
       , sqrt (vcov (m117c)[1,1])
       , sqrt (vcov (m117c)[1,1]+1^2*vcov (m117c)[5,5]+2*1*vcov (m117c)[1,5])
       , NA
       , sqrt (vcov (m117c)[1,1]+1^2*vcov (m117c)[4,4]+2*1*vcov (m117c)[1,4]))))

odd <- seq (1, nrow (coefSpecification03a)*2, by=2); even <- seq (2, nrow (coefSpecification03a)*2, by=2)
(coefSpecification03tab <- data.frame (rbind (coefSpecification03a, seSpecification03a))) ## warnings reported. Don't worry
rownames (coefSpecification03tab) <- c (odd, even)
coefSpecification03tab <- coefSpecification03tab[order (as.numeric (rownames (coefSpecification03tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m100c$N, length (unique (sum.m100c$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m100c$fe$year.f)))
  , c (sum.m101c$N, length (unique (sum.m101c$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m101c$fe$year.f)))
  , c (sum.m102c$N, length (unique (sum.m102c$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m102c$fe$year.f)))
  , c (sum.m103c$N, length (unique (sum.m103c$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m103c$fe$year.f)))
  , c (sum.m103f$N, length (unique (sum.m103f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m103f$fe$year.f)))
  , c (sum.m110c$N, length (unique (sum.m110c$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m110c$fe$year.f)))
  , c (sum.m111c$N, length (unique (sum.m111c$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m111c$fe$year.f)))
  , c (sum.m111f$N, length (unique (sum.m111f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m111f$fe$year.f)))
  , c (sum.m105c$N, length (unique (sum.m105c$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m105c$fe$year.f)))
  , c (sum.m113c$N, length (unique (sum.m113c$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m113c$fe$year.f)))
  , c (sum.m109c$N, length (unique (sum.m109c$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m109c$fe$year.f)))
  , c (sum.m117c$N, length (unique (sum.m117c$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m117c$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefSpecification03tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Adding controls (3): \\emph{oil and gas per capita}$_{t-1}$ (log)"
               , label="T:rSpecificationOil")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (4.3.2) Figure A14

# (4.3.2.1) Marginal effect of growth (t-1) on Pr (breakdown t):

# creating the dataset for the plots
dPlotSpecification03g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotSpecification03g) <- "dataset"
dPlotSpecification03g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotSpecification03g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotSpecification03g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotSpecification03g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotSpecification03g$estimate <- c (coefSpecification03tab[c (29, 33, 31, 35),5], coefSpecification03tab[c (29, 33, 31, 35),9]
                                     , coefSpecification03tab[c (29, 33, 31, 35),6], coefSpecification03tab[c (29, 33, 31, 35),10]
                                     , coefSpecification03tab[c (29, 33, 31, 35),12], coefSpecification03tab[c (29, 33, 31, 35),13]
                                     , coefSpecification03tab[c (29, 33, 31, 35),15], coefSpecification03tab[c (29, 33, 31, 35),16])
dPlotSpecification03g$se <- c (coefSpecification03tab[c (29, 33, 31, 35)+1,5], coefSpecification03tab[c (29, 33, 31, 35)+1,9]
                               , coefSpecification03tab[c (29, 33, 31, 35)+1,6], coefSpecification03tab[c (29, 33, 31, 35)+1,10]
                               , coefSpecification03tab[c (29, 33, 31, 35)+1,12], coefSpecification03tab[c (29, 33, 31, 35)+1,13]
                               , coefSpecification03tab[c (29, 33, 31, 35)+1,15], coefSpecification03tab[c (29, 33, 31, 35)+1,16])
dPlotSpecification03g$ciLow <- with (dPlotSpecification03g, estimate + se*qt (0.025, df=n))
dPlotSpecification03g$ciHigh <- with (dPlotSpecification03g, estimate + se*qt (0.975, df=n))
dPlotSpecification03g <- dPlotSpecification03g[!is.na (dPlotSpecification03g$estimate),]
dPlotSpecification03g$effect <- factor (dPlotSpecification03g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (4.3.2.2) Marginal effect of election (t) on Pr (breakdown t):
dPlotSpecification03el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotSpecification03el) <- "dataset"
dPlotSpecification03el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotSpecification03el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotSpecification03el$growth <- rep (seq (min (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$madddGDPHead_lag), max (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$madddGDPHead_lag), length.out=m), 3)
dPlotSpecification03el$estimate <- with (dPlotSpecification03el, ifelse (
  elType=="actual elections\n(closed)", sum.m103c$coef[2,1]+sum.m103c$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m103c$coef[2,1]+sum.m103c$coef[7,1]+(sum.m103c$coef[3,1]+sum.m103c$coef[5,1])*growth, sum.m111a$coef[2,1]+sum.m111a$coef[4,1]*growth)))
dPlotSpecification03el$se <- with (dPlotSpecification03el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m103c)[2,2] + (growth^2)*vcov (m103c)[3,3] + (2*growth)*vcov (m103c)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m103c)[2,2] + (growth^2)*vcov (m103c)[3,3] + (1^2)*vcov (m103c)[7,7] + (growth^2)*(1^2)*vcov (m103c)[5,5] + (2*growth)*vcov (m103c)[2,3] + (2*1)*vcov (m103c)[2,7] + (2*growth*1)*vcov (m103c)[2,5] + (2*growth*1)*vcov (m103c)[3,7] + (2*1*growth^2)*vcov (m103c)[3,5] + (2*growth*1^2)*vcov (m103c)[7,5]), sqrt (vcov (m111a)[2,2] + (growth^2)*vcov (m111a)[4,4] + (2*growth)*vcov (m111a)[2,4]))))
dPlotSpecification03el$ciLow <- with (dPlotSpecification03el, estimate + se*qt (0.025, df=n))
dPlotSpecification03el$ciHigh <- with (dPlotSpecification03el, estimate + se*qt (0.975, df=n))
dPlotSpecification03el <- dPlotSpecification03el[abs (dPlotSpecification03el$growth) <= h.lim,]

# (4.3.2.3) Drawing the plots

# Specification results for growth|elections (with and without controls)
(pEffectSpecification01 <- ggplot (dPlotSpecification03g[dPlotSpecification03g$elType=="competitive\n& executive",]
                                   , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Specification vs. Placebos for growth|elections
(pEffectSpecification02 <- ggplot (dPlotSpecification03g[dPlotSpecification03g$controls=="no controls",]
                                   , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthSpecification <- ggplot (maddMain[abs (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Specification results for elections|growth
(pEffectSpecification03 <- ggplot (dPlotSpecification03el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthSpecification), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# (4.3.2.4) Exporting the plots
png ("Figures/fig_rSpecificationOil01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecification01
dev.off ()
png ("Figures/fig_rSpecificationOil02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecification02
dev.off ()
png ("Figures/fig_rSpecificationOil03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectSpecification03
dev.off ()


## (4.4) Table A22: Controlling for % of democratic neighbors only
(coefSpecification04a <- cbind (
  c (sum.m100d$coef[1,1], rep (NA, 8+4), sum.m100d$coef[2,1], rep (NA, 4))
  , rep (NA, 18)
  , c (NA, sum.m101d$coef[1,1], rep (NA, 7+4), sum.m101d$coef[2,1], rep (NA, 4))
  , c (sum.m102d$coef[1:3,1], rep (NA, 6+4), sum.m102d$coef[4,1], sum.m102d$coef[1,1], sum.m102d$coef[1,1], sum.m102d$coef[1,1]+sum.m102d$coef[3,1], sum.m102d$coef[1,1]+sum.m102d$coef[3,1])
  , c (sum.m103d$coef[1:7,1], rep (NA, 2+4), sum.m103d$coef[8,1], sum.m103d$coef[1,1], sum.m103d$coef[1,1]+sum.m103d$coef[4,1], sum.m103d$coef[1,1]+sum.m103d$coef[3,1], sum.m103d$coef[1,1]+sum.m103d$coef[3,1]+sum.m103d$coef[4,1]+sum.m103d$coef[5,1])
  , c (sum.m103f$coef[1:7,1], rep (NA, 2+2), sum.m103f$coef[8:10,1], sum.m103f$coef[1,1], sum.m103f$coef[1,1]+sum.m103f$coef[4,1], sum.m103f$coef[1,1]+sum.m103f$coef[3,1], sum.m103f$coef[1,1]+sum.m103f$coef[3,1]+sum.m103f$coef[4,1]+sum.m103f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m110d$coef[1,1], rep (NA, 5), sum.m110d$coef[2,1], rep (NA, 1+4), sum.m110d$coef[3,1], rep (NA, 4))
  , c (sum.m111d$coef[c (1:2,4),1], rep (NA, 4), sum.m111d$coef[c (3,5),1], rep (NA, 2+2), sum.m111d$coef[6,1], sum.m111d$coef[1,1], sum.m111d$coef[1,1]+sum.m111d$coef[5,1], NA, sum.m111d$coef[1,1]+sum.m111d$coef[4,1])
  , c (sum.m111f$coef[c (1:2,4),1], rep (NA, 4), sum.m111f$coef[c (3,5),1], rep (NA, 2), sum.m111f$coef[6:8,1], sum.m111f$coef[1,1], sum.m111f$coef[1,1]+sum.m111f$coef[5,1], NA, sum.m111f$coef[1,1]+sum.m111f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m105d$coef[1:7,1], rep (NA, 2+4), sum.m105d$coef[8,1], sum.m105d$coef[1,1], sum.m105d$coef[1,1]+sum.m105d$coef[4,1], sum.m105d$coef[1,1]+sum.m105d$coef[3,1], sum.m105d$coef[1,1]+sum.m105d$coef[3,1]+sum.m105d$coef[4,1]+sum.m105d$coef[5,1])
  , c (sum.m113d$coef[c (1:2,4),1], rep (NA, 4), sum.m113d$coef[c (3,5),1], rep (NA, 2+2), sum.m113d$coef[6,1],sum.m113d$coef[1,1], sum.m113d$coef[1,1]+sum.m113d$coef[5,1], NA, sum.m113d$coef[1,1]+sum.m113d$coef[4,1])
  , rep (NA, 18)
  , c (sum.m109d$coef[1:7,1], rep (NA, 2+4), sum.m109d$coef[8,1], sum.m109d$coef[1,1], sum.m109d$coef[1,1]+sum.m109d$coef[4,1], sum.m109d$coef[1,1]+sum.m109d$coef[3,1], sum.m109d$coef[1,1]+sum.m109d$coef[3,1]+sum.m109d$coef[4,1]+sum.m109d$coef[5,1])
  , c (sum.m117d$coef[c (1:2,4),1], rep (NA, 4), sum.m117d$coef[c (3,5:7),1], rep (NA, 2), sum.m117d$coef[8,1], sum.m117d$coef[1,1], sum.m117d$coef[1,1]+sum.m117d$coef[5,1], NA, sum.m117d$coef[1,1]+sum.m117d$coef[4,1])))
(seSpecification04a <- cbind (
  c (sum.m100d$coef[1,2], rep (NA, 8+4), sum.m100d$coef[2,2], rep (NA, 4))
  , rep (NA, 18)
  , c (NA, sum.m101d$coef[1,2], rep (NA, 7+4), sum.m101d$coef[2,2], rep (NA, 4))
  , c (sum.m102d$coef[1:3,2], rep (NA, 6+4), sum.m102d$coef[4,2]
       , sqrt (vcov (m102d)[1,1])
       , sqrt (vcov (m102d)[1,1])
       , sqrt (vcov (m102d)[1,1]+1^2*vcov (m102d)[3,3]+2*1*vcov (m102d)[1,3])
       , sqrt (vcov (m102d)[1,1]+1^2*vcov (m102d)[3,3]+2*1*vcov (m102d)[1,3]))
  , c (sum.m103d$coef[1:7,2], rep (NA, 2+4), sum.m103d$coef[8,2]
       , sqrt (vcov (m103d)[1,1])
       , sqrt (vcov (m103d)[1,1]+1^2*vcov (m103d)[4,4]+2*1*vcov (m103d)[1,4])
       , sqrt (vcov (m103d)[1,1]+1^2*vcov (m103d)[3,3]+2*1*vcov (m103d)[1,3])
       , sqrt (vcov (m103d)[1,1]+1^2*vcov (m103d)[3,3]+1^2*vcov (m103d)[4,4]+1^2*1^2*vcov (m103d)[5,5]+2*1*vcov (m103d)[1,3]+2*1*vcov (m103d)[1,4]+2*1*1*vcov (m103d)[1,5]+2*1*1*vcov (m103d)[3,4]+2*1*1^2*vcov (m103d)[3,5]+2*1*1^2*vcov (m103d)[4,5]))
  , c (sum.m103f$coef[1:7,2], rep (NA, 2+2), sum.m103f$coef[8:10,2]
       , sqrt (vcov (m103f)[1,1])
       , sqrt (vcov (m103f)[1,1]+1^2*vcov (m103f)[4,4]+2*1*vcov (m103f)[1,4])
       , sqrt (vcov (m103f)[1,1]+1^2*vcov (m103f)[3,3]+2*1*vcov (m103f)[1,3])
       , sqrt (vcov (m103f)[1,1]+1^2*vcov (m103f)[3,3]+1^2*vcov (m103f)[4,4]+1^2*1^2*vcov (m103f)[5,5]+2*1*vcov (m103f)[1,3]+2*1*vcov (m103f)[1,4]+2*1*1*vcov (m103f)[1,5]+2*1*1*vcov (m103f)[3,4]+2*1*1^2*vcov (m103f)[3,5]+2*1*1^2*vcov (m103f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m110d$coef[1,2], rep (NA, 5), sum.m110d$coef[2,2], rep (NA, 1+4), sum.m110d$coef[3,2], rep (NA, 4))
  , c (sum.m111d$coef[c (1:2,4),2], rep (NA, 4), sum.m111d$coef[c (3,5),2], rep (NA, 2+2), sum.m111d$coef[6,2]
       , sqrt (vcov (m111d)[1,1])
       , sqrt (vcov (m111d)[1,1]+1^2*vcov (m111d)[5,5]+2*1*vcov (m111d)[1,5])
       , NA
       , sqrt (vcov (m111d)[1,1]+1^2*vcov (m111d)[4,4]+2*1*vcov (m111d)[1,4]))
  , c (sum.m111f$coef[c (1:2,4),2], rep (NA, 4), sum.m111f$coef[c (3,5),2], rep (NA, 2), sum.m111f$coef[6:8,2]
       , sqrt (vcov (m111f)[1,1])
       , sqrt (vcov (m111f)[1,1]+1^2*vcov (m111f)[5,5]+2*1*vcov (m111f)[1,5])
       , NA
       , sqrt (vcov (m111f)[1,1]+1^2*vcov (m111f)[4,4]+2*1*vcov (m111f)[1,4]))
  , rep (NA, 18)
  , c (sum.m105d$coef[1:7,2], rep (NA, 2+4), sum.m105d$coef[8,2]
       , sqrt (vcov (m105d)[1,1])
       , sqrt (vcov (m105d)[1,1]+1^2*vcov (m105d)[4,4]+2*1*vcov (m105d)[1,4])
       , sqrt (vcov (m105d)[1,1]+1^2*vcov (m105d)[3,3]+2*1*vcov (m105d)[1,3])
       , sqrt (vcov (m105d)[1,1]+1^2*vcov (m105d)[3,3]+1^2*vcov (m105d)[4,4]+1^2*1^2*vcov (m105d)[5,5]+2*1*vcov (m105d)[1,3]+2*1*vcov (m105d)[1,4]+2*1*1*vcov (m105d)[1,5]+2*1*1*vcov (m105d)[3,4]+2*1*1^2*vcov (m105d)[3,5]+2*1*1^2*vcov (m105d)[4,5]))
  , c (sum.m113d$coef[c (1:2,4),2], rep (NA, 4), sum.m113d$coef[c (3,5),2], rep (NA, 2+2), sum.m113d$coef[6,2]
       , sqrt (vcov (m113d)[1,1])
       , sqrt (vcov (m113d)[1,1]+1^2*vcov (m113d)[5,5]+2*1*vcov (m113d)[1,5])
       , NA
       , sqrt (vcov (m113d)[1,1]+1^2*vcov (m113d)[4,4]+2*1*vcov (m113d)[1,4]))
  , rep (NA, 18)
  , c (sum.m109d$coef[1:7,2], rep (NA, 2+4), sum.m109d$coef[8,2]
       , sqrt (vcov (m109d)[1,1])
       , sqrt (vcov (m109d)[1,1]+1^2*vcov (m109d)[4,4]+2*1*vcov (m109d)[1,4])
       , sqrt (vcov (m109d)[1,1]+1^2*vcov (m109d)[3,3]+2*1*vcov (m109d)[1,3])
       , sqrt (vcov (m109d)[1,1]+1^2*vcov (m109d)[3,3]+1^2*vcov (m109d)[4,4]+1^2*1^2*vcov (m109d)[5,5]+2*1*vcov (m109d)[1,3]+2*1*vcov (m109d)[1,4]+2*1*1*vcov (m109d)[1,5]+2*1*1*vcov (m109d)[3,4]+2*1*1^2*vcov (m109d)[3,5]+2*1*1^2*vcov (m109d)[4,5]))
  , c (sum.m117d$coef[c (1:2,4),2], rep (NA, 4), sum.m117d$coef[c (3,5:7),2], rep (NA, 2), sum.m117d$coef[8,2]
       , sqrt (vcov (m117d)[1,1])
       , sqrt (vcov (m117d)[1,1]+1^2*vcov (m117d)[5,5]+2*1*vcov (m117d)[1,5])
       , NA
       , sqrt (vcov (m117d)[1,1]+1^2*vcov (m117d)[4,4]+2*1*vcov (m117d)[1,4]))))

odd <- seq (1, nrow (coefSpecification04a)*2, by=2); even <- seq (2, nrow (coefSpecification04a)*2, by=2)
(coefSpecification04tab <- data.frame (rbind (coefSpecification04a, seSpecification04a))) ## warnings reported. Don't worry
rownames (coefSpecification04tab) <- c (odd, even)
coefSpecification04tab <- coefSpecification04tab[order (as.numeric (rownames (coefSpecification04tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m100d$N, length (unique (sum.m100d$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m100d$fe$year.f)))
  , c (sum.m101d$N, length (unique (sum.m101d$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m101d$fe$year.f)))
  , c (sum.m102d$N, length (unique (sum.m102d$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m102d$fe$year.f)))
  , c (sum.m103d$N, length (unique (sum.m103d$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m103d$fe$year.f)))
  , c (sum.m103f$N, length (unique (sum.m103f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m103f$fe$year.f)))
  , c (sum.m110d$N, length (unique (sum.m110d$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m110d$fe$year.f)))
  , c (sum.m111d$N, length (unique (sum.m111d$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m111d$fe$year.f)))
  , c (sum.m111f$N, length (unique (sum.m111f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m111f$fe$year.f)))
  , c (sum.m105d$N, length (unique (sum.m105d$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m105d$fe$year.f)))
  , c (sum.m113d$N, length (unique (sum.m113d$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m113d$fe$year.f)))
  , c (sum.m109d$N, length (unique (sum.m109d$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m109d$fe$year.f)))
  , c (sum.m117d$N, length (unique (sum.m117d$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m117d$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefSpecification04tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Adding controls (4): \\emph{proportion of democratic neighbors}$_{t}$"
               , label="T:rSpecificationDemo")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (4.4.2) Figure A15

# (4.4.2.1) Marginal effect of growth (t-1) on Pr (breakdown t):

# creating the dataset for the plots
dPlotSpecification04g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotSpecification04g) <- "dataset"
dPlotSpecification04g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotSpecification04g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotSpecification04g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotSpecification04g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotSpecification04g$estimate <- c (coefSpecification04tab[c (29, 33, 31, 35),5], coefSpecification04tab[c (29, 33, 31, 35),9]
                                     , coefSpecification04tab[c (29, 33, 31, 35),6], coefSpecification04tab[c (29, 33, 31, 35),10]
                                     , coefSpecification04tab[c (29, 33, 31, 35),12], coefSpecification04tab[c (29, 33, 31, 35),13]
                                     , coefSpecification04tab[c (29, 33, 31, 35),15], coefSpecification04tab[c (29, 33, 31, 35),16])
dPlotSpecification04g$se <- c (coefSpecification04tab[c (29, 33, 31, 35)+1,5], coefSpecification04tab[c (29, 33, 31, 35)+1,9]
                               , coefSpecification04tab[c (29, 33, 31, 35)+1,6], coefSpecification04tab[c (29, 33, 31, 35)+1,10]
                               , coefSpecification04tab[c (29, 33, 31, 35)+1,12], coefSpecification04tab[c (29, 33, 31, 35)+1,13]
                               , coefSpecification04tab[c (29, 33, 31, 35)+1,15], coefSpecification04tab[c (29, 33, 31, 35)+1,16])
dPlotSpecification04g$ciLow <- with (dPlotSpecification04g, estimate + se*qt (0.025, df=n))
dPlotSpecification04g$ciHigh <- with (dPlotSpecification04g, estimate + se*qt (0.975, df=n))
dPlotSpecification04g <- dPlotSpecification04g[!is.na (dPlotSpecification04g$estimate),]
dPlotSpecification04g$effect <- factor (dPlotSpecification04g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (4.4.2.2) Marginal effect of election (t) on Pr (breakdown t):
dPlotSpecification04el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotSpecification04el) <- "dataset"
dPlotSpecification04el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotSpecification04el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotSpecification04el$growth <- rep (seq (min (maddMain$madddGDPHead_lag), max (maddMain$madddGDPHead_lag), length.out=m), 3)
dPlotSpecification04el$estimate <- with (dPlotSpecification04el, ifelse (
  elType=="actual elections\n(closed)", sum.m103d$coef[2,1]+sum.m103d$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m103d$coef[2,1]+sum.m103d$coef[7,1]+(sum.m103d$coef[3,1]+sum.m103d$coef[5,1])*growth, sum.m111a$coef[2,1]+sum.m111a$coef[4,1]*growth)))
dPlotSpecification04el$se <- with (dPlotSpecification04el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m103d)[2,2] + (growth^2)*vcov (m103d)[3,3] + (2*growth)*vcov (m103d)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m103d)[2,2] + (growth^2)*vcov (m103d)[3,3] + (1^2)*vcov (m103d)[7,7] + (growth^2)*(1^2)*vcov (m103d)[5,5] + (2*growth)*vcov (m103d)[2,3] + (2*1)*vcov (m103d)[2,7] + (2*growth*1)*vcov (m103d)[2,5] + (2*growth*1)*vcov (m103d)[3,7] + (2*1*growth^2)*vcov (m103d)[3,5] + (2*growth*1^2)*vcov (m103d)[7,5]), sqrt (vcov (m111a)[2,2] + (growth^2)*vcov (m111a)[4,4] + (2*growth)*vcov (m111a)[2,4]))))
dPlotSpecification04el$ciLow <- with (dPlotSpecification04el, estimate + se*qt (0.025, df=n))
dPlotSpecification04el$ciHigh <- with (dPlotSpecification04el, estimate + se*qt (0.975, df=n))
dPlotSpecification04el <- dPlotSpecification04el[abs (dPlotSpecification04el$growth) <= h.lim,]

# (4.4.2.3) Drawing the plots

# Specification results for growth|elections (with and without controls)
(pEffectSpecification01 <- ggplot (dPlotSpecification04g[dPlotSpecification04g$elType=="competitive\n& executive",]
                                   , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Specification vs. Placebos for growth|elections
(pEffectSpecification02 <- ggplot (dPlotSpecification04g[dPlotSpecification04g$controls=="no controls",]
                                   , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthSpecification <- ggplot (maddMain[abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Specification results for elections|growth
(pEffectSpecification03 <- ggplot (dPlotSpecification04el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthSpecification), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# (4.4.2.4) Exporting the plots
png ("Figures/fig_rSpecificationDemo01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecification01
dev.off ()
png ("Figures/fig_rSpecificationDemo02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecification02
dev.off ()
png ("Figures/fig_rSpecificationDemo03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectSpecification03
dev.off ()


## (4.5) Table A23: Including all controls simultaneously
(coefSpecification05a <- cbind (
  c (sum.m100f$coef[1,1], rep (NA, 8+2), sum.m100f$coef[2:4,1], rep (NA, 4))
  , rep (NA, 18)
  , c (NA, sum.m101f$coef[1,1], rep (NA, 7+2), sum.m101f$coef[2:4,1], rep (NA, 4))
  , c (sum.m102f$coef[1:3,1], rep (NA, 6+2), sum.m102f$coef[4:6,1], sum.m102f$coef[1,1], sum.m102f$coef[1,1], sum.m102f$coef[1,1]+sum.m102f$coef[3,1], sum.m102f$coef[1,1]+sum.m102f$coef[3,1])
  , c (sum.m103f$coef[1:7,1], rep (NA, 2+2), sum.m103f$coef[8:10,1], sum.m103f$coef[1,1], sum.m103f$coef[1,1]+sum.m103f$coef[4,1], sum.m103f$coef[1,1]+sum.m103f$coef[3,1], sum.m103f$coef[1,1]+sum.m103f$coef[3,1]+sum.m103f$coef[4,1]+sum.m103f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m110f$coef[1,1], rep (NA, 5), sum.m110f$coef[2,1], rep (NA, 1+2), sum.m110f$coef[3:5,1], rep (NA, 4))
  , c (sum.m111f$coef[c (1:2,4),1], rep (NA, 4), sum.m111f$coef[c (3,5),1], rep (NA, 2), sum.m111f$coef[6:8,1], sum.m111f$coef[1,1], sum.m111f$coef[1,1]+sum.m111f$coef[5,1], NA, sum.m111f$coef[1,1]+sum.m111f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m105f$coef[1:7,1], rep (NA, 2+2), sum.m105f$coef[8:10,1], sum.m105f$coef[1,1], sum.m105f$coef[1,1]+sum.m105f$coef[4,1], sum.m105f$coef[1,1]+sum.m105f$coef[3,1], sum.m105f$coef[1,1]+sum.m105f$coef[3,1]+sum.m105f$coef[4,1]+sum.m105f$coef[5,1])
  , c (sum.m113f$coef[c (1:2,4),1], rep (NA, 4), sum.m113f$coef[c (3,5),1], rep (NA, 2), sum.m113f$coef[6:8,1],sum.m113f$coef[1,1], sum.m113f$coef[1,1]+sum.m113f$coef[5,1], NA, sum.m113f$coef[1,1]+sum.m113f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m109f$coef[1:7,1], rep (NA, 2+2), sum.m109f$coef[8:10,1], sum.m109f$coef[1,1], sum.m109f$coef[1,1]+sum.m109f$coef[4,1], sum.m109f$coef[1,1]+sum.m109f$coef[3,1], sum.m109f$coef[1,1]+sum.m109f$coef[3,1]+sum.m109f$coef[4,1]+sum.m109f$coef[5,1])
  , c (sum.m117f$coef[c (1:2,4),1], rep (NA, 4), sum.m117f$coef[c (3,5:10),1], sum.m117f$coef[1,1], sum.m117f$coef[1,1]+sum.m117f$coef[5,1], NA, sum.m117f$coef[1,1]+sum.m117f$coef[4,1])))
(seSpecification05a <- cbind (
  c (sum.m100f$coef[1,2], rep (NA, 8+2), sum.m100f$coef[2:4,2], rep (NA, 4))
  , rep (NA, 18)
  , c (NA, sum.m101f$coef[1,2], rep (NA, 7+2), sum.m101f$coef[2:4,2], rep (NA, 4))
  , c (sum.m102f$coef[1:3,2], rep (NA, 6+2), sum.m102f$coef[4:6,2]
       , sqrt (vcov (m102f)[1,1])
       , sqrt (vcov (m102f)[1,1])
       , sqrt (vcov (m102f)[1,1]+1^2*vcov (m102f)[3,3]+2*1*vcov (m102f)[1,3])
       , sqrt (vcov (m102f)[1,1]+1^2*vcov (m102f)[3,3]+2*1*vcov (m102f)[1,3]))
  , c (sum.m103f$coef[1:7,2], rep (NA, 2+2), sum.m103f$coef[8:10,2]
       , sqrt (vcov (m103f)[1,1])
       , sqrt (vcov (m103f)[1,1]+1^2*vcov (m103f)[4,4]+2*1*vcov (m103f)[1,4])
       , sqrt (vcov (m103f)[1,1]+1^2*vcov (m103f)[3,3]+2*1*vcov (m103f)[1,3])
       , sqrt (vcov (m103f)[1,1]+1^2*vcov (m103f)[3,3]+1^2*vcov (m103f)[4,4]+1^2*1^2*vcov (m103f)[5,5]+2*1*vcov (m103f)[1,3]+2*1*vcov (m103f)[1,4]+2*1*1*vcov (m103f)[1,5]+2*1*1*vcov (m103f)[3,4]+2*1*1^2*vcov (m103f)[3,5]+2*1*1^2*vcov (m103f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m110f$coef[1,2], rep (NA, 5), sum.m110f$coef[2,2], rep (NA, 1+2), sum.m110f$coef[3:5,2], rep (NA, 4))
  , c (sum.m111f$coef[c (1:2,4),2], rep (NA, 4), sum.m111f$coef[c (3,5),2], rep (NA, 2), sum.m111f$coef[6:8,2]
       , sqrt (vcov (m111f)[1,1])
       , sqrt (vcov (m111f)[1,1]+1^2*vcov (m111f)[5,5]+2*1*vcov (m111f)[1,5])
       , NA
       , sqrt (vcov (m111f)[1,1]+1^2*vcov (m111f)[4,4]+2*1*vcov (m111f)[1,4]))
  , rep (NA, 18)
  , c (sum.m105f$coef[1:7,2], rep (NA, 2+2), sum.m105f$coef[8:10,2]
       , sqrt (vcov (m105f)[1,1])
       , sqrt (vcov (m105f)[1,1]+1^2*vcov (m105f)[4,4]+2*1*vcov (m105f)[1,4])
       , sqrt (vcov (m105f)[1,1]+1^2*vcov (m105f)[3,3]+2*1*vcov (m105f)[1,3])
       , sqrt (vcov (m105f)[1,1]+1^2*vcov (m105f)[3,3]+1^2*vcov (m105f)[4,4]+1^2*1^2*vcov (m105f)[5,5]+2*1*vcov (m105f)[1,3]+2*1*vcov (m105f)[1,4]+2*1*1*vcov (m105f)[1,5]+2*1*1*vcov (m105f)[3,4]+2*1*1^2*vcov (m105f)[3,5]+2*1*1^2*vcov (m105f)[4,5]))
  , c (sum.m113f$coef[c (1:2,4),2], rep (NA, 4), sum.m113f$coef[c (3,5),2], rep (NA, 2), sum.m113f$coef[6:8,2]
       , sqrt (vcov (m113f)[1,1])
       , sqrt (vcov (m113f)[1,1]+1^2*vcov (m113f)[5,5]+2*1*vcov (m113f)[1,5])
       , NA
       , sqrt (vcov (m113f)[1,1]+1^2*vcov (m113f)[4,4]+2*1*vcov (m113f)[1,4]))
  , rep (NA, 18)
  , c (sum.m109f$coef[1:7,2], rep (NA, 2+2), sum.m109f$coef[8:10,2]
       , sqrt (vcov (m109f)[1,1])
       , sqrt (vcov (m109f)[1,1]+1^2*vcov (m109f)[4,4]+2*1*vcov (m109f)[1,4])
       , sqrt (vcov (m109f)[1,1]+1^2*vcov (m109f)[3,3]+2*1*vcov (m109f)[1,3])
       , sqrt (vcov (m109f)[1,1]+1^2*vcov (m109f)[3,3]+1^2*vcov (m109f)[4,4]+1^2*1^2*vcov (m109f)[5,5]+2*1*vcov (m109f)[1,3]+2*1*vcov (m109f)[1,4]+2*1*1*vcov (m109f)[1,5]+2*1*1*vcov (m109f)[3,4]+2*1*1^2*vcov (m109f)[3,5]+2*1*1^2*vcov (m109f)[4,5]))
  , c (sum.m117f$coef[c (1:2,4),2], rep (NA, 4), sum.m117f$coef[c (3,5:10),2]
       , sqrt (vcov (m117f)[1,1])
       , sqrt (vcov (m117f)[1,1]+1^2*vcov (m117f)[5,5]+2*1*vcov (m117f)[1,5])
       , NA
       , sqrt (vcov (m117f)[1,1]+1^2*vcov (m117f)[4,4]+2*1*vcov (m117f)[1,4]))))

odd <- seq (1, nrow (coefSpecification05a)*2, by=2); even <- seq (2, nrow (coefSpecification05a)*2, by=2)
(coefSpecification05tab <- data.frame (rbind (coefSpecification05a, seSpecification05a))) ## warnings reported. Don't worry
rownames (coefSpecification05tab) <- c (odd, even)
coefSpecification05tab <- coefSpecification05tab[order (as.numeric (rownames (coefSpecification05tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m100f$N, length (unique (sum.m100f$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m100f$fe$year.f)))
  , c (sum.m101f$N, length (unique (sum.m101f$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m101f$fe$year.f)))
  , c (sum.m102f$N, length (unique (sum.m102f$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m102f$fe$year.f)))
  , c (sum.m103f$N, length (unique (sum.m103f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m103f$fe$year.f)))
  , c (sum.m110f$N, length (unique (sum.m110f$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m110f$fe$year.f)))
  , c (sum.m111f$N, length (unique (sum.m111f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m111f$fe$year.f)))
  , c (sum.m105f$N, length (unique (sum.m105f$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m105f$fe$year.f)))
  , c (sum.m113f$N, length (unique (sum.m113f$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m113f$fe$year.f)))
  , c (sum.m109f$N, length (unique (sum.m109f$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m109f$fe$year.f)))
  , c (sum.m117f$N, length (unique (sum.m117f$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m117f$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{3}{c}{\\textbf{actual elections}} & & \\multicolumn{2}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-6} \\cmidrule{8-9} \\cmidrule{11-12} \\cmidrule{14-15} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & & \\multicolumn{1}{c}{(5)} & \\multicolumn{1}{c}{(6)} & & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{15}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefSpecification05tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Adding controls (5): \\emph{GDP per capita}$_{t-1}$ (log), \\emph{oil and gas per capita}$_{t-1}$ (log) and \\emph{proportion of democratic neighbors}$_{t}$"
               , label="T:rSpecificationAll")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (4.5.2) Figure A16

# (4.5.2.1) Marginal effect of growth (t-1) on Pr (breakdown t):

# creating the dataset for the plots
dPlotSpecification05g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotSpecification05g) <- "dataset"
dPlotSpecification05g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotSpecification05g$controls <- factor (c (rep ("w/controls", 8), rep ("no controls", 8), rep ("w/controls", 16)))
dPlotSpecification05g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotSpecification05g$n <- Ns00[1,sort (rep (c (4,4,6,6,7:10), 4))]
dPlotSpecification05g$estimate <- c (coefSpecification05tab[c (29, 33, 31, 35),5], coefSpecification05tab[c (29, 33, 31, 35),8]
                                     , rep (NA, 8)
                                     , coefSpecification05tab[c (29, 33, 31, 35),10], coefSpecification05tab[c (29, 33, 31, 35),11]
                                     , coefSpecification05tab[c (29, 33, 31, 35),13], coefSpecification05tab[c (29, 33, 31, 35),14])
dPlotSpecification05g$se <- c (coefSpecification05tab[c (29, 33, 31, 35)+1,5], coefSpecification05tab[c (29, 33, 31, 35)+1,8]
                               , rep (NA, 8)
                               , coefSpecification05tab[c (29, 33, 31, 35)+1,10], coefSpecification05tab[c (29, 33, 31, 35)+1,11]
                               , coefSpecification05tab[c (29, 33, 31, 35)+1,13], coefSpecification05tab[c (29, 33, 31, 35)+1,14])
dPlotSpecification05g$ciLow <- with (dPlotSpecification05g, estimate + se*qt (0.025, df=n))
dPlotSpecification05g$ciHigh <- with (dPlotSpecification05g, estimate + se*qt (0.975, df=n))
dPlotSpecification05g <- dPlotSpecification05g[!is.na (dPlotSpecification05g$estimate) & dPlotSpecification05g$controls=="w/controls",]
dPlotSpecification05g$effect <- factor (dPlotSpecification05g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (4.5.2.2) Marginal effect of election (t) on Pr (breakdown t):
dPlotSpecification05el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotSpecification05el) <- "dataset"
dPlotSpecification05el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotSpecification05el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,6], m))
dPlotSpecification05el$growth <- rep (seq (min (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$madddGDPHead_lag), max (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$madddGDPHead_lag), length.out=m), 3)
dPlotSpecification05el$estimate <- with (dPlotSpecification05el, ifelse (
  elType=="actual elections\n(closed)", sum.m103f$coef[2,1]+sum.m103f$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m103f$coef[2,1]+sum.m103f$coef[7,1]+(sum.m103f$coef[3,1]+sum.m103f$coef[5,1])*growth, sum.m111a$coef[2,1]+sum.m111a$coef[4,1]*growth)))
dPlotSpecification05el$se <- with (dPlotSpecification05el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m103f)[2,2] + (growth^2)*vcov (m103f)[3,3] + (2*growth)*vcov (m103f)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m103f)[2,2] + (growth^2)*vcov (m103f)[3,3] + (1^2)*vcov (m103f)[7,7] + (growth^2)*(1^2)*vcov (m103f)[5,5] + (2*growth)*vcov (m103f)[2,3] + (2*1)*vcov (m103f)[2,7] + (2*growth*1)*vcov (m103f)[2,5] + (2*growth*1)*vcov (m103f)[3,7] + (2*1*growth^2)*vcov (m103f)[3,5] + (2*growth*1^2)*vcov (m103f)[7,5]), sqrt (vcov (m111a)[2,2] + (growth^2)*vcov (m111a)[4,4] + (2*growth)*vcov (m111a)[2,4]))))
dPlotSpecification05el$ciLow <- with (dPlotSpecification05el, estimate + se*qt (0.025, df=n))
dPlotSpecification05el$ciHigh <- with (dPlotSpecification05el, estimate + se*qt (0.975, df=n))
dPlotSpecification05el <- dPlotSpecification05el[abs (dPlotSpecification05el$growth) <= h.lim,]

# (4.5.2.3) Drawing the plots

# Specification results for growth|elections (with and without controls)
(pEffectSpecification01 <- ggplot (dPlotSpecification05g[dPlotSpecification05g$elType=="competitive\n& executive",]
                                   , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Specification vs. Placebos for growth|elections
(pEffectSpecification02 <- ggplot (dPlotSpecification05g
                                   , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthSpecification <- ggplot (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),][abs (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Specification results for elections|growth
(pEffectSpecification03 <- ggplot (dPlotSpecification05el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthSpecification), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# (4.5.2.4) Exporting the plots
png ("Figures/fig_rSpecificationAll01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecification01
dev.off ()
png ("Figures/fig_rSpecificationAll02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecification02
dev.off ()
png ("Figures/fig_rSpecificationAll03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectSpecification03
dev.off ()


## (4.6) Table A24: Alternative breakdown dates
(coefSpecification06a <- cbind (
  c (sum.m301a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m311a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m311c$coef[1:3,1], rep (NA, 6+5), sum.m311c$coef[1,1], sum.m311c$coef[1,1], sum.m311c$coef[1,1]+sum.m311c$coef[3,1], sum.m311c$coef[1,1]+sum.m311c$coef[3,1])
  , c (sum.m311e$coef[1:7,1], rep (NA, 2+5), sum.m311e$coef[1,1], sum.m311e$coef[1,1]+sum.m311e$coef[4,1], sum.m311e$coef[1,1]+sum.m311e$coef[3,1], sum.m311e$coef[1,1]+sum.m311e$coef[3,1]+sum.m311e$coef[4,1]+sum.m311e$coef[5,1])
  , c (sum.m311f$coef[1:7,1], rep (NA, 2+2), sum.m311f$coef[8:10,1], sum.m311f$coef[1,1], sum.m311f$coef[1,1]+sum.m311f$coef[4,1], sum.m311f$coef[1,1]+sum.m311f$coef[3,1], sum.m311f$coef[1,1]+sum.m311f$coef[3,1]+sum.m311f$coef[4,1]+sum.m311f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m321a$coef[1,1], rep (NA, 5), sum.m321a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m321e$coef[c (1:2,4),1], rep (NA, 4), sum.m321e$coef[c (3,5),1], rep (NA, 5), sum.m321e$coef[1,1], sum.m321e$coef[1,1]+sum.m321e$coef[5,1], NA, sum.m321e$coef[1,1]+sum.m321e$coef[4,1])
  , c (sum.m321f$coef[c (1:2,4),1], rep (NA, 4), sum.m321f$coef[c (3,5),1], rep (NA, 2), sum.m321f$coef[6:8,1], sum.m321f$coef[1,1], sum.m321f$coef[1,1]+sum.m321f$coef[5,1], NA, sum.m321f$coef[1,1]+sum.m321f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m311g$coef[1:7,1], rep (NA, 2+5), sum.m311g$coef[1,1], sum.m311g$coef[1,1]+sum.m311g$coef[4,1], sum.m311g$coef[1,1]+sum.m311g$coef[3,1], sum.m311g$coef[1,1]+sum.m311g$coef[3,1]+sum.m311g$coef[4,1]+sum.m311g$coef[5,1])
  , c (sum.m321g$coef[c (1:2,4),1], rep (NA, 4), sum.m321g$coef[c (3,5),1], rep (NA, 5), sum.m321g$coef[1,1], sum.m321g$coef[1,1]+sum.m321g$coef[5,1], NA, sum.m321g$coef[1,1]+sum.m321g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m311i$coef[1:7,1], rep (NA, 2+5), sum.m311i$coef[1,1], sum.m311i$coef[1,1]+sum.m311i$coef[4,1], sum.m311i$coef[1,1]+sum.m311i$coef[3,1], sum.m311i$coef[1,1]+sum.m311i$coef[3,1]+sum.m311i$coef[4,1]+sum.m311i$coef[5,1])
  , c (sum.m321i$coef[c (1:2,4),1], rep (NA, 4), sum.m321i$coef[c (3,5:7),1], rep (NA, 3), sum.m321i$coef[1,1], sum.m321i$coef[1,1]+sum.m321i$coef[5,1], NA, sum.m321i$coef[1,1]+sum.m321i$coef[4,1])))
(seSpecification06a <- cbind (
  c (sum.m301a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m311a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m311c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m311c)[1,1])
       , sqrt (vcov (m311c)[1,1])
       , sqrt (vcov (m311c)[1,1]+1^2*vcov (m311c)[3,3]+2*1*vcov (m311c)[1,3])
       , sqrt (vcov (m311c)[1,1]+1^2*vcov (m311c)[3,3]+2*1*vcov (m311c)[1,3]))
  , c (sum.m311e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m311e)[1,1])
       , sqrt (vcov (m311e)[1,1]+1^2*vcov (m311e)[4,4]+2*1*vcov (m311e)[1,4])
       , sqrt (vcov (m311e)[1,1]+1^2*vcov (m311e)[3,3]+2*1*vcov (m311e)[1,3])
       , sqrt (vcov (m311e)[1,1]+1^2*vcov (m311e)[3,3]+1^2*vcov (m311e)[4,4]+1^2*1^2*vcov (m311e)[5,5]+2*1*vcov (m311e)[1,3]+2*1*vcov (m311e)[1,4]+2*1*1*vcov (m311e)[1,5]+2*1*1*vcov (m311e)[3,4]+2*1*1^2*vcov (m311e)[3,5]+2*1*1^2*vcov (m311e)[4,5]))
  , c (sum.m311f$coef[1:7,2], rep (NA, 2+2), sum.m311f$coef[8:10,2]
       , sqrt (vcov (m311f)[1,1])
       , sqrt (vcov (m311f)[1,1]+1^2*vcov (m311f)[4,4]+2*1*vcov (m311f)[1,4])
       , sqrt (vcov (m311f)[1,1]+1^2*vcov (m311f)[3,3]+2*1*vcov (m311f)[1,3])
       , sqrt (vcov (m311f)[1,1]+1^2*vcov (m311f)[3,3]+1^2*vcov (m311f)[4,4]+1^2*1^2*vcov (m311f)[5,5]+2*1*vcov (m311f)[1,3]+2*1*vcov (m311f)[1,4]+2*1*1*vcov (m311f)[1,5]+2*1*1*vcov (m311f)[3,4]+2*1*1^2*vcov (m311f)[3,5]+2*1*1^2*vcov (m311f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m321a$coef[1,2], rep (NA, 5), sum.m321a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m321e$coef[c (1:2,4),2], rep (NA, 4), sum.m321e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m321e)[1,1])
       , sqrt (vcov (m321e)[1,1]+1^2*vcov (m321e)[5,5]+2*1*vcov (m321e)[1,5])
       , NA
       , sqrt (vcov (m321e)[1,1]+1^2*vcov (m321e)[4,4]+2*1*vcov (m321e)[1,4]))
  , c (sum.m321f$coef[c (1:2,4),2], rep (NA, 4), sum.m321f$coef[c (3,5),2], rep (NA, 2), sum.m321f$coef[6:8,2]
       , sqrt (vcov (m321f)[1,1])
       , sqrt (vcov (m321f)[1,1]+1^2*vcov (m321f)[5,5]+2*1*vcov (m321f)[1,5])
       , NA
       , sqrt (vcov (m321f)[1,1]+1^2*vcov (m321f)[4,4]+2*1*vcov (m321f)[1,4]))
  , rep (NA, 18)
  , c (sum.m311g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m311g)[1,1])
       , sqrt (vcov (m311g)[1,1]+1^2*vcov (m311g)[4,4]+2*1*vcov (m311g)[1,4])
       , sqrt (vcov (m311g)[1,1]+1^2*vcov (m311g)[3,3]+2*1*vcov (m311g)[1,3])
       , sqrt (vcov (m311g)[1,1]+1^2*vcov (m311g)[3,3]+1^2*vcov (m311g)[4,4]+1^2*1^2*vcov (m311g)[5,5]+2*1*vcov (m311g)[1,3]+2*1*vcov (m311g)[1,4]+2*1*1*vcov (m311g)[1,5]+2*1*1*vcov (m311g)[3,4]+2*1*1^2*vcov (m311g)[3,5]+2*1*1^2*vcov (m311g)[4,5]))
  , c (sum.m321g$coef[c (1:2,4),2], rep (NA, 4), sum.m321g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m321g)[1,1])
       , sqrt (vcov (m321g)[1,1]+1^2*vcov (m321g)[5,5]+2*1*vcov (m321g)[1,5])
       , NA
       , sqrt (vcov (m321g)[1,1]+1^2*vcov (m321g)[4,4]+2*1*vcov (m321g)[1,4]))
  , rep (NA, 18)
  , c (sum.m311i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m311i)[1,1])
       , sqrt (vcov (m311i)[1,1]+1^2*vcov (m311i)[4,4]+2*1*vcov (m311i)[1,4])
       , sqrt (vcov (m311i)[1,1]+1^2*vcov (m311i)[3,3]+2*1*vcov (m311i)[1,3])
       , sqrt (vcov (m311i)[1,1]+1^2*vcov (m311i)[3,3]+1^2*vcov (m311i)[4,4]+1^2*1^2*vcov (m311i)[5,5]+2*1*vcov (m311i)[1,3]+2*1*vcov (m311i)[1,4]+2*1*1*vcov (m311i)[1,5]+2*1*1*vcov (m311i)[3,4]+2*1*1^2*vcov (m311i)[3,5]+2*1*1^2*vcov (m311i)[4,5]))
  , c (sum.m321i$coef[c (1:2,4),2], rep (NA, 4), sum.m321i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m321i)[1,1])
       , sqrt (vcov (m321i)[1,1]+1^2*vcov (m321i)[5,5]+2*1*vcov (m321i)[1,5])
       , NA
       , sqrt (vcov (m321i)[1,1]+1^2*vcov (m321i)[4,4]+2*1*vcov (m321i)[1,4]))))

odd <- seq (1, nrow (coefSpecification06a)*2, by=2); even <- seq (2, nrow (coefSpecification06a)*2, by=2)
(coefSpecification06tab <- data.frame (rbind (coefSpecification06a, seSpecification06a))) ## warnings reported. Don't worry
rownames (coefSpecification06tab) <- c (odd, even)
coefSpecification06tab <- coefSpecification06tab[order (as.numeric (rownames (coefSpecification06tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m301a$N, length (unique (sum.m301a$fe$idRegime)), length (unique (maddMain[maddMain$dateFailPost==0,]$country)), length (unique (sum.m301a$fe$year.f)))
  , c (sum.m311a$N, length (unique (sum.m311a$fe$idRegime)), length (unique (maddMain[maddMain$dateFailPost==0,]$country)), length (unique (sum.m311a$fe$year.f)))
  , c (sum.m311c$N, length (unique (sum.m311c$fe$idRegime)), length (unique (maddMain[maddMain$dateFailPost==0,]$country)), length (unique (sum.m311c$fe$year.f)))
  , c (sum.m311e$N, length (unique (sum.m311e$fe$idRegime)), length (unique (maddMain[maddMain$dateFailPost==0,]$country)), length (unique (sum.m311e$fe$year.f)))
  , c (sum.m311f$N, length (unique (sum.m311f$fe$idRegime)), length (unique (maddMain[maddMain$dateFailPost==0 & !is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m311f$fe$year.f)))
  , c (sum.m321a$N, length (unique (sum.m321a$fe$idRegime)), length (unique (maddMain[maddMain$dateFailPost==0,]$country)), length (unique (sum.m321a$fe$year.f)))
  , c (sum.m321e$N, length (unique (sum.m321e$fe$idRegime)), length (unique (maddMain[maddMain$dateFailPost==0,]$country)), length (unique (sum.m321e$fe$year.f)))
  , c (sum.m321f$N, length (unique (sum.m321f$fe$idRegime)), length (unique (maddMain[maddMain$dateFailPost==0 & !is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m321f$fe$year.f)))
  , c (sum.m311g$N, length (unique (sum.m311g$fe$idRegime)), length (unique (maddMain[maddMain$dateFailPost==0,]$country)), length (unique (sum.m311g$fe$year.f)))
  , c (sum.m321g$N, length (unique (sum.m321g$fe$idRegime)), length (unique (maddMain[maddMain$dateFailPost==0,]$country)), length (unique (sum.m321g$fe$year.f)))
  , c (sum.m311i$N, length (unique (sum.m311i$fe$idRegime)), length (unique (maddMain[maddMain$dateFailPost==0,]$country)), length (unique (sum.m311i$fe$year.f)))
  , c (sum.m321i$N, length (unique (sum.m321i$fe$idRegime)), length (unique (maddMain[maddMain$dateFailPost==0,]$country)), length (unique (sum.m321i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefSpecification06tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Alternative breakdown dates"
               , label="T:rSpecificationFail")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (4.6.2) Figure A17

# (4.6.2.1) Marginal effect of growth (t-1) on Pr (breakdown t):

# creating the dataset for the plots
dPlotSpecification06g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotSpecification06g) <- "dataset"
dPlotSpecification06g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotSpecification06g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotSpecification06g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotSpecification06g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotSpecification06g$estimate <- c (coefSpecification06tab[c (29, 33, 31, 35),5], coefSpecification06tab[c (29, 33, 31, 35),9]
                                     , coefSpecification06tab[c (29, 33, 31, 35),6], coefSpecification06tab[c (29, 33, 31, 35),10]
                                     , coefSpecification06tab[c (29, 33, 31, 35),12], coefSpecification06tab[c (29, 33, 31, 35),13]
                                     , coefSpecification06tab[c (29, 33, 31, 35),15], coefSpecification06tab[c (29, 33, 31, 35),16])
dPlotSpecification06g$se <- c (coefSpecification06tab[c (29, 33, 31, 35)+1,5], coefSpecification06tab[c (29, 33, 31, 35)+1,9]
                               , coefSpecification06tab[c (29, 33, 31, 35)+1,6], coefSpecification06tab[c (29, 33, 31, 35)+1,10]
                               , coefSpecification06tab[c (29, 33, 31, 35)+1,12], coefSpecification06tab[c (29, 33, 31, 35)+1,13]
                               , coefSpecification06tab[c (29, 33, 31, 35)+1,15], coefSpecification06tab[c (29, 33, 31, 35)+1,16])
dPlotSpecification06g$ciLow <- with (dPlotSpecification06g, estimate + se*qt (0.025, df=n))
dPlotSpecification06g$ciHigh <- with (dPlotSpecification06g, estimate + se*qt (0.975, df=n))
dPlotSpecification06g <- dPlotSpecification06g[!is.na (dPlotSpecification06g$estimate),]
dPlotSpecification06g$effect <- factor (dPlotSpecification06g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (4.6.2.2) Marginal effect of election (t) on Pr (breakdown t):
dPlotSpecification06el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotSpecification06el) <- "dataset"
dPlotSpecification06el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotSpecification06el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotSpecification06el$growth <- rep (seq (min (maddMain[maddMain$dateFailPost==0,]$madddGDPHead_lag), max (maddMain[maddMain$dateFailPost==0,]$madddGDPHead_lag), length.out=m), 3)
dPlotSpecification06el$estimate <- with (dPlotSpecification06el, ifelse (
  elType=="actual elections\n(closed)", sum.m311e$coef[2,1]+sum.m311e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m311e$coef[2,1]+sum.m311e$coef[7,1]+(sum.m311e$coef[3,1]+sum.m311e$coef[5,1])*growth, sum.m321e$coef[2,1]+sum.m321e$coef[4,1]*growth)))
dPlotSpecification06el$se <- with (dPlotSpecification06el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m311e)[2,2] + (growth^2)*vcov (m311e)[3,3] + (2*growth)*vcov (m311e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m311e)[2,2] + (growth^2)*vcov (m311e)[3,3] + (1^2)*vcov (m311e)[7,7] + (growth^2)*(1^2)*vcov (m311e)[5,5] + (2*growth)*vcov (m311e)[2,3] + (2*1)*vcov (m311e)[2,7] + (2*growth*1)*vcov (m311e)[2,5] + (2*growth*1)*vcov (m311e)[3,7] + (2*1*growth^2)*vcov (m311e)[3,5] + (2*growth*1^2)*vcov (m311e)[7,5]), sqrt (vcov (m321e)[2,2] + (growth^2)*vcov (m321e)[4,4] + (2*growth)*vcov (m321e)[2,4]))))
dPlotSpecification06el$ciLow <- with (dPlotSpecification06el, estimate + se*qt (0.025, df=n))
dPlotSpecification06el$ciHigh <- with (dPlotSpecification06el, estimate + se*qt (0.975, df=n))
dPlotSpecification06el <- dPlotSpecification06el[abs (dPlotSpecification06el$growth) <= h.lim,]

# (4.6.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectSpecification01 <- ggplot (dPlotSpecification06g[dPlotSpecification06g$elType=="competitive\n& executive",]
                                   , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectSpecification02 <- ggplot (dPlotSpecification06g[dPlotSpecification06g$controls=="no controls",]
                                   , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthSpecification <- ggplot (maddMain[maddMain$dateFailPost==0 & abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectSpecification03 <- ggplot (dPlotSpecification06el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthSpecification), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# (4.6.2.4) Exporting the plots
png ("Figures/fig_rSpecificationFail01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecification01
dev.off ()
png ("Figures/fig_rSpecificationFail02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecification02
dev.off ()
png ("Figures/fig_rSpecificationFail03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectSpecification03
dev.off ()


## (4.7) Table A25: Survival models (cloglog)
(coefSpecification07a <- cbind (
  c (coef.m302a[1,1], rep (NA, 8+2), coef.m302a[2,1], rep (NA, 2+4))
  , rep (NA, 18)
  , c (NA, coef.m312a[1,1], rep (NA, 7+2), coef.m312a[2,1], rep (NA, 2+4))
  , c (coef.m312c[1:3,1], rep (NA, 6+2), coef.m312c[4,1], rep (NA, 2), coef.m312c[1,1], coef.m312c[1,1], coef.m312c[1,1]+coef.m312c[3,1], coef.m312c[1,1]+coef.m312c[3,1])
  , c (coef.m312e[1:7,1], rep (NA, 2+2), coef.m312e[8,1], rep (NA, 2), coef.m312e[1,1], coef.m312e[1,1]+coef.m312e[4,1], coef.m312e[1,1]+coef.m312e[3,1], coef.m312e[1,1]+coef.m312e[3,1]+coef.m312e[4,1]+coef.m312e[5,1])
  , c (coef.m312f[1:7,1], rep (NA, 2+2), coef.m312f[8:10,1], coef.m312f[1,1], coef.m312f[1,1]+coef.m312f[4,1], coef.m312f[1,1]+coef.m312f[3,1], coef.m312f[1,1]+coef.m312f[3,1]+coef.m312f[4,1]+coef.m312f[5,1])
  , rep (NA, 18)
  , c (NA, coef.m322a[1,1], rep (NA, 5), coef.m322a[2,1], rep (NA, 1+2), coef.m322a[3,1], rep (NA, 2+4))
  , c (coef.m322e[c (1:2,4),1], rep (NA, 4), coef.m322e[c (3,5),1], rep (NA, 2), coef.m322e[6,1], rep (NA, 2), coef.m322e[1,1], coef.m322e[1,1]+coef.m322e[5,1], NA, coef.m322e[1,1]+coef.m322e[4,1])
  , c (coef.m322f[c (1:2,4),1], rep (NA, 4), coef.m322f[c (3,5),1], rep (NA, 2), coef.m322f[6:8,1], coef.m322f[1,1], coef.m322f[1,1]+coef.m322f[5,1], NA, coef.m322f[1,1]+coef.m322f[4,1])
  , rep (NA, 18)
  , c (coef.m312g[1:7,1], rep (NA, 2+2), coef.m312g[8,1], rep (NA, 2), coef.m312g[1,1], coef.m312g[1,1]+coef.m312g[4,1], coef.m312g[1,1]+coef.m312g[3,1], coef.m312g[1,1]+coef.m312g[3,1]+coef.m312g[4,1]+coef.m312g[5,1])
  , c (coef.m322g[c (1:2,4),1], rep (NA, 4), coef.m322g[c (3,5),1], rep (NA, 2), coef.m322g[6,1], rep (NA, 2), coef.m322g[1,1], coef.m322g[1,1]+coef.m322g[5,1], NA, coef.m322g[1,1]+coef.m322g[4,1])
  , rep (NA, 18)
  , c (coef.m312i[1:7,1], rep (NA, 2+2), coef.m312i[8,1], rep (NA, 2), coef.m312i[1,1], coef.m312i[1,1]+coef.m312i[4,1], coef.m312i[1,1]+coef.m312i[3,1], coef.m312i[1,1]+coef.m312i[3,1]+coef.m312i[4,1]+coef.m312i[5,1])
  , c (coef.m322i[c (1:2,4),1], rep (NA, 4), coef.m322i[c (3,5:8),1], rep (NA, 2), coef.m322i[1,1], coef.m322i[1,1]+coef.m322i[5,1], NA, coef.m322i[1,1]+coef.m322i[4,1])))
(seSpecification07a <- cbind (
  c (coef.m302a[1,2], rep (NA, 8+2), coef.m302a[2,2], rep (NA, 2+4))
  , rep (NA, 18)
  , c (NA, coef.m312a[1,2], rep (NA, 7+2), coef.m312a[2,2], rep (NA, 2+4))
  , c (coef.m312c[1:3,2], rep (NA, 6+2), coef.m312c[4,2], rep (NA, 2)
       , sqrt (vcov (m312c)[1,1])
       , sqrt (vcov (m312c)[1,1])
       , sqrt (vcov (m312c)[1,1]+1^2*vcov (m312c)[3,3]+2*1*vcov (m312c)[1,3])
       , sqrt (vcov (m312c)[1,1]+1^2*vcov (m312c)[3,3]+2*1*vcov (m312c)[1,3]))
  , c (coef.m312e[1:7,2], rep (NA, 2+2), coef.m312e[8,2], rep (NA, 2)
       , sqrt (vcov (m312e)[1,1])
       , sqrt (vcov (m312e)[1,1]+1^2*vcov (m312e)[4,4]+2*1*vcov (m312e)[1,4])
       , sqrt (vcov (m312e)[1,1]+1^2*vcov (m312e)[3,3]+2*1*vcov (m312e)[1,3])
       , sqrt (vcov (m312e)[1,1]+1^2*vcov (m312e)[3,3]+1^2*vcov (m312e)[4,4]+1^2*1^2*vcov (m312e)[5,5]+2*1*vcov (m312e)[1,3]+2*1*vcov (m312e)[1,4]+2*1*1*vcov (m312e)[1,5]+2*1*1*vcov (m312e)[3,4]+2*1*1^2*vcov (m312e)[3,5]+2*1*1^2*vcov (m312e)[4,5]))
  , c (coef.m312f[1:7,2], rep (NA, 2+2), coef.m312f[8:10,2]
       , sqrt (vcov (m312f)[1,1])
       , sqrt (vcov (m312f)[1,1]+1^2*vcov (m312f)[4,4]+2*1*vcov (m312f)[1,4])
       , sqrt (vcov (m312f)[1,1]+1^2*vcov (m312f)[3,3]+2*1*vcov (m312f)[1,3])
       , sqrt (vcov (m312f)[1,1]+1^2*vcov (m312f)[3,3]+1^2*vcov (m312f)[4,4]+1^2*1^2*vcov (m312f)[5,5]+2*1*vcov (m312f)[1,3]+2*1*vcov (m312f)[1,4]+2*1*1*vcov (m312f)[1,5]+2*1*1*vcov (m312f)[3,4]+2*1*1^2*vcov (m312f)[3,5]+2*1*1^2*vcov (m312f)[4,5]))
  , rep (NA, 18)
  , c (NA, coef.m322a[1,2], rep (NA, 5), coef.m322a[2,2], rep (NA, 1+2), coef.m322a[3,2], rep (NA, 2+4))
  , c (coef.m322e[c (1:2,4),2], rep (NA, 4), coef.m322e[c (3,5),2], rep (NA, 2), coef.m322e[6,2], rep (NA, 2)
       , sqrt (vcov (m322e)[1,1])
       , sqrt (vcov (m322e)[1,1]+1^2*vcov (m322e)[5,5]+2*1*vcov (m322e)[1,5])
       , NA
       , sqrt (vcov (m322e)[1,1]+1^2*vcov (m322e)[4,4]+2*1*vcov (m322e)[1,4]))
  , c (coef.m322f[c (1:2,4),2], rep (NA, 4), coef.m322f[c (3,5),2], rep (NA, 2), coef.m322f[6:8,2]
       , sqrt (vcov (m322f)[1,1])
       , sqrt (vcov (m322f)[1,1]+1^2*vcov (m322f)[5,5]+2*1*vcov (m322f)[1,5])
       , NA
       , sqrt (vcov (m322f)[1,1]+1^2*vcov (m322f)[4,4]+2*1*vcov (m322f)[1,4]))
  , rep (NA, 18)
  , c (coef.m312g[1:7,2], rep (NA, 2+2), coef.m312g[8,2], rep (NA, 2)
       , sqrt (vcov (m312g)[1,1])
       , sqrt (vcov (m312g)[1,1]+1^2*vcov (m312g)[4,4]+2*1*vcov (m312g)[1,4])
       , sqrt (vcov (m312g)[1,1]+1^2*vcov (m312g)[3,3]+2*1*vcov (m312g)[1,3])
       , sqrt (vcov (m312g)[1,1]+1^2*vcov (m312g)[3,3]+1^2*vcov (m312g)[4,4]+1^2*1^2*vcov (m312g)[5,5]+2*1*vcov (m312g)[1,3]+2*1*vcov (m312g)[1,4]+2*1*1*vcov (m312g)[1,5]+2*1*1*vcov (m312g)[3,4]+2*1*1^2*vcov (m312g)[3,5]+2*1*1^2*vcov (m312g)[4,5]))
  , c (coef.m322g[c (1:2,4),2], rep (NA, 4), coef.m322g[c (3,5),2], rep (NA, 2), coef.m322g[6,2], rep (NA, 2)
       , sqrt (vcov (m322g)[1,1])
       , sqrt (vcov (m322g)[1,1]+1^2*vcov (m322g)[5,5]+2*1*vcov (m322g)[1,5])
       , NA
       , sqrt (vcov (m322g)[1,1]+1^2*vcov (m322g)[4,4]+2*1*vcov (m322g)[1,4]))
  , rep (NA, 18)
  , c (coef.m312i[1:7,2], rep (NA, 2+2), coef.m312i[8,2], rep (NA, 2)
       , sqrt (vcov (m312i)[1,1])
       , sqrt (vcov (m312i)[1,1]+1^2*vcov (m312i)[4,4]+2*1*vcov (m312i)[1,4])
       , sqrt (vcov (m312i)[1,1]+1^2*vcov (m312i)[3,3]+2*1*vcov (m312i)[1,3])
       , sqrt (vcov (m312i)[1,1]+1^2*vcov (m312i)[3,3]+1^2*vcov (m312i)[4,4]+1^2*1^2*vcov (m312i)[5,5]+2*1*vcov (m312i)[1,3]+2*1*vcov (m312i)[1,4]+2*1*1*vcov (m312i)[1,5]+2*1*1*vcov (m312i)[3,4]+2*1*1^2*vcov (m312i)[3,5]+2*1*1^2*vcov (m312i)[4,5]))
  , c (coef.m322i[c (1:2,4),2], rep (NA, 4), coef.m322i[c (3,5:8),2], rep (NA, 2)
       , sqrt (vcov (m322i)[1,1])
       , sqrt (vcov (m322i)[1,1]+1^2*vcov (m322i)[5,5]+2*1*vcov (m322i)[1,5])
       , NA
       , sqrt (vcov (m322i)[1,1]+1^2*vcov (m322i)[4,4]+2*1*vcov (m322i)[1,4]))))

odd <- seq (1, nrow (coefSpecification07a)*2, by=2); even <- seq (2, nrow (coefSpecification07a)*2, by=2)
(coefSpecification07tab <- data.frame (rbind (coefSpecification07a, seSpecification07a))) ## warnings reported. Don't worry
rownames (coefSpecification07tab) <- c (odd, even)
coefSpecification07tab <- coefSpecification07tab[order (as.numeric (rownames (coefSpecification07tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m302a$df[1]+sum.m302a$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m312a$df[1]+sum.m312a$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m312c$df[1]+sum.m312c$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m312e$df[1]+sum.m312e$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m312f$df[1]+sum.m312f$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m322a$df[1]+sum.m322a$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m322e$df[1]+sum.m322e$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m322f$df[1]+sum.m322f$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m312g$df[1]+sum.m312g$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m322g$df[1]+sum.m322g$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m312i$df[1]+sum.m312i$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m322i$df[1]+sum.m322i$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))))

(Fit00 <- cbind (
  c (AIC (m302a), BIC (m302a))
  , c (AIC (m312a), BIC (m312a))
  , c (AIC (m312c), BIC (m312c))
  , c (AIC (m312e), BIC (m312e))
  , c (AIC (m312f), BIC (m312f))
  , c (AIC (m322a), BIC (m322a))
  , c (AIC (m322e), BIC (m322e))
  , c (AIC (m322f), BIC (m322f))
  , c (AIC (m312g), BIC (m312g))
  , c (AIC (m322g), BIC (m322g))
  , c (AIC (m312i), BIC (m312i))
  , c (AIC (m322i), BIC (m322i))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$} (linear predictor)} \\\\ \\midrule \n")

aic <- paste ("\\midrule AIC & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,12],0)), "} \\\\ \n")
bic <- paste ("BIC & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,12],0)), "} \\\\ \n")
n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , aic, bic, n.obs#, n.reg, n.ctry
)
print (xtable (cbind (rows, parSE (coefSpecification07tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Survival models (1): Cloglog link"
               , label="T:rSpecificationCloglog")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (4.7.2) Figure A18

# (4.7.2.1) Marginal effect of growth (t-1) on Linear predictor:

# creating the dataset for the plots
dPlotSpecification07g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotSpecification07g) <- "dataset"
dPlotSpecification07g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotSpecification07g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotSpecification07g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotSpecification07g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotSpecification07g$estimate <- c (coefSpecification07tab[c (29, 33, 31, 35),5], coefSpecification07tab[c (29, 33, 31, 35),9]
                                     , coefSpecification07tab[c (29, 33, 31, 35),6], coefSpecification07tab[c (29, 33, 31, 35),10]
                                     , coefSpecification07tab[c (29, 33, 31, 35),12], coefSpecification07tab[c (29, 33, 31, 35),13]
                                     , coefSpecification07tab[c (29, 33, 31, 35),15], coefSpecification07tab[c (29, 33, 31, 35),16])
dPlotSpecification07g$se <- c (coefSpecification07tab[c (29, 33, 31, 35)+1,5], coefSpecification07tab[c (29, 33, 31, 35)+1,9]
                               , coefSpecification07tab[c (29, 33, 31, 35)+1,6], coefSpecification07tab[c (29, 33, 31, 35)+1,10]
                               , coefSpecification07tab[c (29, 33, 31, 35)+1,12], coefSpecification07tab[c (29, 33, 31, 35)+1,13]
                               , coefSpecification07tab[c (29, 33, 31, 35)+1,15], coefSpecification07tab[c (29, 33, 31, 35)+1,16])
dPlotSpecification07g$ciLow <- with (dPlotSpecification07g, estimate + se*qt (0.025, df=n))
dPlotSpecification07g$ciHigh <- with (dPlotSpecification07g, estimate + se*qt (0.975, df=n))
dPlotSpecification07g <- dPlotSpecification07g[!is.na (dPlotSpecification07g$estimate),]
dPlotSpecification07g$effect <- factor (dPlotSpecification07g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (4.7.2.2) Marginal effect of election (t) on Linear predictor:
dPlotSpecification07el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotSpecification07el) <- "dataset"
dPlotSpecification07el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotSpecification07el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotSpecification07el$growth <- rep (seq (min (maddMain$madddGDPHead_lag), max (maddMain$madddGDPHead_lag), length.out=m), 3)
dPlotSpecification07el$estimate <- with (dPlotSpecification07el, ifelse (
  elType=="actual elections\n(closed)", coef.m312e[2,1]+coef.m312e[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", coef.m312e[2,1]+coef.m312e[7,1]+(coef.m312e[3,1]+coef.m312e[5,1])*growth, coef.m322e[2,1]+coef.m322e[4,1]*growth)))
dPlotSpecification07el$se <- with (dPlotSpecification07el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m312e)[2,2] + (growth^2)*vcov (m312e)[3,3] + (2*growth)*vcov (m312e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m312e)[2,2] + (growth^2)*vcov (m312e)[3,3] + (1^2)*vcov (m312e)[7,7] + (growth^2)*(1^2)*vcov (m312e)[5,5] + (2*growth)*vcov (m312e)[2,3] + (2*1)*vcov (m312e)[2,7] + (2*growth*1)*vcov (m312e)[2,5] + (2*growth*1)*vcov (m312e)[3,7] + (2*1*growth^2)*vcov (m312e)[3,5] + (2*growth*1^2)*vcov (m312e)[7,5]), sqrt (vcov (m322e)[2,2] + (growth^2)*vcov (m322e)[4,4] + (2*growth)*vcov (m322e)[2,4]))))
dPlotSpecification07el$ciLow <- with (dPlotSpecification07el, estimate + se*qt (0.025, df=n))
dPlotSpecification07el$ciHigh <- with (dPlotSpecification07el, estimate + se*qt (0.975, df=n))
dPlotSpecification07el <- dPlotSpecification07el[abs (dPlotSpecification07el$growth) <= h.lim,]

# (4.7.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectSpecificationCloglog01 <- ggplot (dPlotSpecification07g[dPlotSpecification07g$elType=="competitive\n& executive",]
                                          , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non linear predictor")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectSpecificationCloglog02 <- ggplot (dPlotSpecification07g[dPlotSpecification07g$controls=="no controls",]
                                          , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non linear predictor")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthSpecificationCloglog <- ggplot (maddMain[abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectSpecificationCloglog03 <- ggplot (dPlotSpecification07el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthSpecificationCloglog), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non linear predictor"))

# (4.7.2.4) Exporting the plots
png ("Figures/fig_rSpecificationCloglog01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecificationCloglog01
dev.off ()
png ("Figures/fig_rSpecificationCloglog02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecificationCloglog02
dev.off ()
png ("Figures/fig_rSpecificationCloglog03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectSpecificationCloglog03
dev.off ()


## (4.8) Table A26: Survival models (probit, simple)
(coefSpecification08a <- cbind (
  c (coef.m303a[1,1], rep (NA, 8+2), coef.m303a[2,1], rep (NA, 2+4))
  , rep (NA, 18)
  , c (NA, coef.m313a[1,1], rep (NA, 7+2), coef.m313a[2,1], rep (NA, 2+4))
  , c (coef.m313c[1:3,1], rep (NA, 6+2), coef.m313c[4,1], rep (NA, 2), coef.m313c[1,1], coef.m313c[1,1], coef.m313c[1,1]+coef.m313c[3,1], coef.m313c[1,1]+coef.m313c[3,1])
  , c (coef.m313e[1:7,1], rep (NA, 2+2), coef.m313e[8,1], rep (NA, 2), coef.m313e[1,1], coef.m313e[1,1]+coef.m313e[4,1], coef.m313e[1,1]+coef.m313e[3,1], coef.m313e[1,1]+coef.m313e[3,1]+coef.m313e[4,1]+coef.m313e[5,1])
  , c (coef.m313f[1:7,1], rep (NA, 2+2), coef.m313f[8:10,1], coef.m313f[1,1], coef.m313f[1,1]+coef.m313f[4,1], coef.m313f[1,1]+coef.m313f[3,1], coef.m313f[1,1]+coef.m313f[3,1]+coef.m313f[4,1]+coef.m313f[5,1])
  , rep (NA, 18)
  , c (NA, coef.m323a[1,1], rep (NA, 5), coef.m323a[2,1], rep (NA, 1+2), coef.m323a[3,1], rep (NA, 2+4))
  , c (coef.m323e[c (1:2,4),1], rep (NA, 4), coef.m323e[c (3,5),1], rep (NA, 2), coef.m323e[6,1], rep (NA, 2), coef.m323e[1,1], coef.m323e[1,1]+coef.m323e[5,1], NA, coef.m323e[1,1]+coef.m323e[4,1])
  , c (coef.m323f[c (1:2,4),1], rep (NA, 4), coef.m323f[c (3,5),1], rep (NA, 2), coef.m323f[6:8,1], coef.m323f[1,1], coef.m323f[1,1]+coef.m323f[5,1], NA, coef.m323f[1,1]+coef.m323f[4,1])
  , rep (NA, 18)
  , c (coef.m313g[1:7,1], rep (NA, 2+2), coef.m313g[8,1], rep (NA, 2), coef.m313g[1,1], coef.m313g[1,1]+coef.m313g[4,1], coef.m313g[1,1]+coef.m313g[3,1], coef.m313g[1,1]+coef.m313g[3,1]+coef.m313g[4,1]+coef.m313g[5,1])
  , c (coef.m323g[c (1:2,4),1], rep (NA, 4), coef.m323g[c (3,5),1], rep (NA, 2), coef.m323g[6,1], rep (NA, 2), coef.m323g[1,1], coef.m323g[1,1]+coef.m323g[5,1], NA, coef.m323g[1,1]+coef.m323g[4,1])
  , rep (NA, 18)
  , c (coef.m313i[1:7,1], rep (NA, 2+2), coef.m313i[8,1], rep (NA, 2), coef.m313i[1,1], coef.m313i[1,1]+coef.m313i[4,1], coef.m313i[1,1]+coef.m313i[3,1], coef.m313i[1,1]+coef.m313i[3,1]+coef.m313i[4,1]+coef.m313i[5,1])
  , c (coef.m323i[c (1:2,4),1], rep (NA, 4), coef.m323i[c (3,5:8),1], rep (NA, 2), coef.m323i[1,1], coef.m323i[1,1]+coef.m323i[5,1], NA, coef.m323i[1,1]+coef.m323i[4,1])))
(seSpecification08a <- cbind (
  c (coef.m303a[1,2], rep (NA, 8+2), coef.m303a[2,2], rep (NA, 2+4))
  , rep (NA, 18)
  , c (NA, coef.m313a[1,2], rep (NA, 7+2), coef.m313a[2,2], rep (NA, 2+4))
  , c (coef.m313c[1:3,2], rep (NA, 6+2), coef.m313c[4,2], rep (NA, 2)
       , sqrt (vcov (m313c)[1,1])
       , sqrt (vcov (m313c)[1,1])
       , sqrt (vcov (m313c)[1,1]+1^2*vcov (m313c)[3,3]+2*1*vcov (m313c)[1,3])
       , sqrt (vcov (m313c)[1,1]+1^2*vcov (m313c)[3,3]+2*1*vcov (m313c)[1,3]))
  , c (coef.m313e[1:7,2], rep (NA, 2+2), coef.m313e[8,2], rep (NA, 2)
       , sqrt (vcov (m313e)[1,1])
       , sqrt (vcov (m313e)[1,1]+1^2*vcov (m313e)[4,4]+2*1*vcov (m313e)[1,4])
       , sqrt (vcov (m313e)[1,1]+1^2*vcov (m313e)[3,3]+2*1*vcov (m313e)[1,3])
       , sqrt (vcov (m313e)[1,1]+1^2*vcov (m313e)[3,3]+1^2*vcov (m313e)[4,4]+1^2*1^2*vcov (m313e)[5,5]+2*1*vcov (m313e)[1,3]+2*1*vcov (m313e)[1,4]+2*1*1*vcov (m313e)[1,5]+2*1*1*vcov (m313e)[3,4]+2*1*1^2*vcov (m313e)[3,5]+2*1*1^2*vcov (m313e)[4,5]))
  , c (coef.m313f[1:7,2], rep (NA, 2+2), coef.m313f[8:10,2]
       , sqrt (vcov (m313f)[1,1])
       , sqrt (vcov (m313f)[1,1]+1^2*vcov (m313f)[4,4]+2*1*vcov (m313f)[1,4])
       , sqrt (vcov (m313f)[1,1]+1^2*vcov (m313f)[3,3]+2*1*vcov (m313f)[1,3])
       , sqrt (vcov (m313f)[1,1]+1^2*vcov (m313f)[3,3]+1^2*vcov (m313f)[4,4]+1^2*1^2*vcov (m313f)[5,5]+2*1*vcov (m313f)[1,3]+2*1*vcov (m313f)[1,4]+2*1*1*vcov (m313f)[1,5]+2*1*1*vcov (m313f)[3,4]+2*1*1^2*vcov (m313f)[3,5]+2*1*1^2*vcov (m313f)[4,5]))
  , rep (NA, 18)
  , c (NA, coef.m323a[1,2], rep (NA, 5), coef.m323a[2,2], rep (NA, 1+2), coef.m323a[3,2], rep (NA, 2+4))
  , c (coef.m323e[c (1:2,4),2], rep (NA, 4), coef.m323e[c (3,5),2], rep (NA, 2), coef.m323e[6,2], rep (NA, 2)
       , sqrt (vcov (m323e)[1,1])
       , sqrt (vcov (m323e)[1,1]+1^2*vcov (m323e)[5,5]+2*1*vcov (m323e)[1,5])
       , NA
       , sqrt (vcov (m323e)[1,1]+1^2*vcov (m323e)[4,4]+2*1*vcov (m323e)[1,4]))
  , c (coef.m323f[c (1:2,4),2], rep (NA, 4), coef.m323f[c (3,5),2], rep (NA, 2), coef.m323f[6:8,2]
       , sqrt (vcov (m323f)[1,1])
       , sqrt (vcov (m323f)[1,1]+1^2*vcov (m323f)[5,5]+2*1*vcov (m323f)[1,5])
       , NA
       , sqrt (vcov (m323f)[1,1]+1^2*vcov (m323f)[4,4]+2*1*vcov (m323f)[1,4]))
  , rep (NA, 18)
  , c (coef.m313g[1:7,2], rep (NA, 2+2), coef.m313g[8,2], rep (NA, 2)
       , sqrt (vcov (m313g)[1,1])
       , sqrt (vcov (m313g)[1,1]+1^2*vcov (m313g)[4,4]+2*1*vcov (m313g)[1,4])
       , sqrt (vcov (m313g)[1,1]+1^2*vcov (m313g)[3,3]+2*1*vcov (m313g)[1,3])
       , sqrt (vcov (m313g)[1,1]+1^2*vcov (m313g)[3,3]+1^2*vcov (m313g)[4,4]+1^2*1^2*vcov (m313g)[5,5]+2*1*vcov (m313g)[1,3]+2*1*vcov (m313g)[1,4]+2*1*1*vcov (m313g)[1,5]+2*1*1*vcov (m313g)[3,4]+2*1*1^2*vcov (m313g)[3,5]+2*1*1^2*vcov (m313g)[4,5]))
  , c (coef.m323g[c (1:2,4),2], rep (NA, 4), coef.m323g[c (3,5),2], rep (NA, 2), coef.m323g[6,2], rep (NA, 2)
       , sqrt (vcov (m323g)[1,1])
       , sqrt (vcov (m323g)[1,1]+1^2*vcov (m323g)[5,5]+2*1*vcov (m323g)[1,5])
       , NA
       , sqrt (vcov (m323g)[1,1]+1^2*vcov (m323g)[4,4]+2*1*vcov (m323g)[1,4]))
  , rep (NA, 18)
  , c (coef.m313i[1:7,2], rep (NA, 2+2), coef.m313i[8,2], rep (NA, 2)
       , sqrt (vcov (m313i)[1,1])
       , sqrt (vcov (m313i)[1,1]+1^2*vcov (m313i)[4,4]+2*1*vcov (m313i)[1,4])
       , sqrt (vcov (m313i)[1,1]+1^2*vcov (m313i)[3,3]+2*1*vcov (m313i)[1,3])
       , sqrt (vcov (m313i)[1,1]+1^2*vcov (m313i)[3,3]+1^2*vcov (m313i)[4,4]+1^2*1^2*vcov (m313i)[5,5]+2*1*vcov (m313i)[1,3]+2*1*vcov (m313i)[1,4]+2*1*1*vcov (m313i)[1,5]+2*1*1*vcov (m313i)[3,4]+2*1*1^2*vcov (m313i)[3,5]+2*1*1^2*vcov (m313i)[4,5]))
  , c (coef.m323i[c (1:2,4),2], rep (NA, 4), coef.m323i[c (3,5:8),2], rep (NA, 2)
       , sqrt (vcov (m323i)[1,1])
       , sqrt (vcov (m323i)[1,1]+1^2*vcov (m323i)[5,5]+2*1*vcov (m323i)[1,5])
       , NA
       , sqrt (vcov (m323i)[1,1]+1^2*vcov (m323i)[4,4]+2*1*vcov (m323i)[1,4]))))

odd <- seq (1, nrow (coefSpecification08a)*2, by=2); even <- seq (2, nrow (coefSpecification08a)*2, by=2)
(coefSpecification08tab <- data.frame (rbind (coefSpecification08a, seSpecification08a))) ## warnings reported. Don't worry
rownames (coefSpecification08tab) <- c (odd, even)
coefSpecification08tab <- coefSpecification08tab[order (as.numeric (rownames (coefSpecification08tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m303a$df[1]+sum.m303a$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m313a$df[1]+sum.m313a$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m313c$df[1]+sum.m313c$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m313e$df[1]+sum.m313e$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m313f$df[1]+sum.m313f$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m323a$df[1]+sum.m323a$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m323e$df[1]+sum.m323e$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m323f$df[1]+sum.m323f$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m313g$df[1]+sum.m313g$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m323g$df[1]+sum.m323g$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m313i$df[1]+sum.m313i$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m323i$df[1]+sum.m323i$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))))

(Fit00 <- cbind (
  c (AIC (m303a), BIC (m303a))
  , c (AIC (m313a), BIC (m313a))
  , c (AIC (m313c), BIC (m313c))
  , c (AIC (m313e), BIC (m313e))
  , c (AIC (m313f), BIC (m313f))
  , c (AIC (m323a), BIC (m323a))
  , c (AIC (m323e), BIC (m323e))
  , c (AIC (m323f), BIC (m323f))
  , c (AIC (m313g), BIC (m313g))
  , c (AIC (m323g), BIC (m323g))
  , c (AIC (m313i), BIC (m313i))
  , c (AIC (m323i), BIC (m323i))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$} (linear predictor)} \\\\ \\midrule \n")

aic <- paste ("\\midrule AIC & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,12],0)), "} \\\\ \n")
bic <- paste ("BIC & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,12],0)), "} \\\\ \n")
n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , aic, bic, n.obs#, n.reg, n.ctry
)
print (xtable (cbind (rows, parSE (coefSpecification08tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Survival models (2): Probit link"
               , label="T:rSpecificationProbit02")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (4.8.2) Figure A19

# (4.8.2.1) Marginal effect of growth (t-1) on Linear predictor:

# creating the dataset for the plots
dPlotSpecification08g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotSpecification08g) <- "dataset"
dPlotSpecification08g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotSpecification08g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotSpecification08g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotSpecification08g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotSpecification08g$estimate <- c (coefSpecification08tab[c (29, 33, 31, 35),5], coefSpecification08tab[c (29, 33, 31, 35),9]
                                     , coefSpecification08tab[c (29, 33, 31, 35),6], coefSpecification08tab[c (29, 33, 31, 35),10]
                                     , coefSpecification08tab[c (29, 33, 31, 35),12], coefSpecification08tab[c (29, 33, 31, 35),13]
                                     , coefSpecification08tab[c (29, 33, 31, 35),15], coefSpecification08tab[c (29, 33, 31, 35),16])
dPlotSpecification08g$se <- c (coefSpecification08tab[c (29, 33, 31, 35)+1,5], coefSpecification08tab[c (29, 33, 31, 35)+1,9]
                               , coefSpecification08tab[c (29, 33, 31, 35)+1,6], coefSpecification08tab[c (29, 33, 31, 35)+1,10]
                               , coefSpecification08tab[c (29, 33, 31, 35)+1,12], coefSpecification08tab[c (29, 33, 31, 35)+1,13]
                               , coefSpecification08tab[c (29, 33, 31, 35)+1,15], coefSpecification08tab[c (29, 33, 31, 35)+1,16])
dPlotSpecification08g$ciLow <- with (dPlotSpecification08g, estimate + se*qt (0.025, df=n))
dPlotSpecification08g$ciHigh <- with (dPlotSpecification08g, estimate + se*qt (0.975, df=n))
dPlotSpecification08g <- dPlotSpecification08g[!is.na (dPlotSpecification08g$estimate),]
dPlotSpecification08g$effect <- factor (dPlotSpecification08g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (4.8.2.2) Marginal effect of election (t) on Linear predictor:
dPlotSpecification08el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotSpecification08el) <- "dataset"
dPlotSpecification08el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotSpecification08el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotSpecification08el$growth <- rep (seq (min (maddMain$madddGDPHead_lag), max (maddMain$madddGDPHead_lag), length.out=m), 3)
dPlotSpecification08el$estimate <- with (dPlotSpecification08el, ifelse (
  elType=="actual elections\n(closed)", coef.m313e[2,1]+coef.m313e[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", coef.m313e[2,1]+coef.m313e[7,1]+(coef.m313e[3,1]+coef.m313e[5,1])*growth, coef.m323e[2,1]+coef.m323e[4,1]*growth)))
dPlotSpecification08el$se <- with (dPlotSpecification08el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m313e)[2,2] + (growth^2)*vcov (m313e)[3,3] + (2*growth)*vcov (m313e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m313e)[2,2] + (growth^2)*vcov (m313e)[3,3] + (1^2)*vcov (m313e)[7,7] + (growth^2)*(1^2)*vcov (m313e)[5,5] + (2*growth)*vcov (m313e)[2,3] + (2*1)*vcov (m313e)[2,7] + (2*growth*1)*vcov (m313e)[2,5] + (2*growth*1)*vcov (m313e)[3,7] + (2*1*growth^2)*vcov (m313e)[3,5] + (2*growth*1^2)*vcov (m313e)[7,5]), sqrt (vcov (m323e)[2,2] + (growth^2)*vcov (m323e)[4,4] + (2*growth)*vcov (m323e)[2,4]))))
dPlotSpecification08el$ciLow <- with (dPlotSpecification08el, estimate + se*qt (0.025, df=n))
dPlotSpecification08el$ciHigh <- with (dPlotSpecification08el, estimate + se*qt (0.975, df=n))
dPlotSpecification08el <- dPlotSpecification08el[abs (dPlotSpecification08el$growth) <= h.lim,]

# (4.8.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectSpecificationProbit01 <- ggplot (dPlotSpecification08g[dPlotSpecification08g$elType=="competitive\n& executive",]
                                         , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non linear predictor")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectSpecificationProbit02 <- ggplot (dPlotSpecification08g[dPlotSpecification08g$controls=="no controls",]
                                         , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non linear predictor")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthSpecificationProbit <- ggplot (maddMain[abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectSpecificationProbit03 <- ggplot (dPlotSpecification08el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthSpecificationProbit), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non linear predictor"))

# (4.8.2.4) Exporting the plots
png ("Figures/fig_rSpecificationProbit01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecificationProbit01
dev.off ()
png ("Figures/fig_rSpecificationProbit02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecificationProbit02
dev.off ()
png ("Figures/fig_rSpecificationProbit03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectSpecificationProbit03
dev.off ()


## (4.9) Table A27: Survival models (probit, means)
(coefSpecification09a <- cbind (
  c (coef.m304a[1,1], rep (NA, 8+2), coef.m304a[2,1], rep (NA, 2+4))
  , rep (NA, 18)
  , c (NA, coef.m314a[1,1], rep (NA, 7+2), coef.m314a[2,1], rep (NA, 2+4))
  , c (coef.m314c[1:3,1], rep (NA, 6+2), coef.m314c[4,1], rep (NA, 2), coef.m314c[1,1], coef.m314c[1,1], coef.m314c[1,1]+coef.m314c[3,1], coef.m314c[1,1]+coef.m314c[3,1])
  , c (coef.m314e[1:7,1], rep (NA, 2+2), coef.m314e[8,1], rep (NA, 2), coef.m314e[1,1], coef.m314e[1,1]+coef.m314e[4,1], coef.m314e[1,1]+coef.m314e[3,1], coef.m314e[1,1]+coef.m314e[3,1]+coef.m314e[4,1]+coef.m314e[5,1])
  , c (coef.m314f[1:7,1], rep (NA, 2+2), coef.m314f[8:10,1], coef.m314f[1,1], coef.m314f[1,1]+coef.m314f[4,1], coef.m314f[1,1]+coef.m314f[3,1], coef.m314f[1,1]+coef.m314f[3,1]+coef.m314f[4,1]+coef.m314f[5,1])
  , rep (NA, 18)
  , c (NA, coef.m324a[1,1], rep (NA, 5), coef.m324a[2,1], rep (NA, 1+2), coef.m324a[3,1], rep (NA, 2+4))
  , c (coef.m324e[c (1:2,4),1], rep (NA, 4), coef.m324e[c (3,5),1], rep (NA, 2), coef.m324e[6,1], rep (NA, 2), coef.m324e[1,1], coef.m324e[1,1]+coef.m324e[5,1], NA, coef.m324e[1,1]+coef.m324e[4,1])
  , c (coef.m324f[c (1:2,4),1], rep (NA, 4), coef.m324f[c (3,5),1], rep (NA, 2), coef.m324f[6:8,1], coef.m324f[1,1], coef.m324f[1,1]+coef.m324f[5,1], NA, coef.m324f[1,1]+coef.m324f[4,1])
  , rep (NA, 18)
  , c (coef.m314g[1:7,1], rep (NA, 2+2), coef.m314g[8,1], rep (NA, 2), coef.m314g[1,1], coef.m314g[1,1]+coef.m314g[4,1], coef.m314g[1,1]+coef.m314g[3,1], coef.m314g[1,1]+coef.m314g[3,1]+coef.m314g[4,1]+coef.m314g[5,1])
  , c (coef.m324g[c (1:2,4),1], rep (NA, 4), coef.m324g[c (3,5),1], rep (NA, 2), coef.m324g[6,1], rep (NA, 2), coef.m324g[1,1], coef.m324g[1,1]+coef.m324g[5,1], NA, coef.m324g[1,1]+coef.m324g[4,1])
  , rep (NA, 18)
  , c (coef.m314i[1:7,1], rep (NA, 2+2), coef.m314i[8,1], rep (NA, 2), coef.m314i[1,1], coef.m314i[1,1]+coef.m314i[4,1], coef.m314i[1,1]+coef.m314i[3,1], coef.m314i[1,1]+coef.m314i[3,1]+coef.m314i[4,1]+coef.m314i[5,1])
  , c (coef.m324i[c (1:2,4),1], rep (NA, 4), coef.m324i[c (3,5:8),1], rep (NA, 2), coef.m324i[1,1], coef.m324i[1,1]+coef.m324i[5,1], NA, coef.m324i[1,1]+coef.m324i[4,1])))
(seSpecification09a <- cbind (
  c (coef.m304a[1,2], rep (NA, 8+2), coef.m304a[2,2], rep (NA, 2+4))
  , rep (NA, 18)
  , c (NA, coef.m314a[1,2], rep (NA, 7+2), coef.m314a[2,2], rep (NA, 2+4))
  , c (coef.m314c[1:3,2], rep (NA, 6+2), coef.m314c[4,2], rep (NA, 2)
       , sqrt (vcov (m314c)[1,1])
       , sqrt (vcov (m314c)[1,1])
       , sqrt (vcov (m314c)[1,1]+1^2*vcov (m314c)[3,3]+2*1*vcov (m314c)[1,3])
       , sqrt (vcov (m314c)[1,1]+1^2*vcov (m314c)[3,3]+2*1*vcov (m314c)[1,3]))
  , c (coef.m314e[1:7,2], rep (NA, 2+2), coef.m314e[8,2], rep (NA, 2)
       , sqrt (vcov (m314e)[1,1])
       , sqrt (vcov (m314e)[1,1]+1^2*vcov (m314e)[4,4]+2*1*vcov (m314e)[1,4])
       , sqrt (vcov (m314e)[1,1]+1^2*vcov (m314e)[3,3]+2*1*vcov (m314e)[1,3])
       , sqrt (vcov (m314e)[1,1]+1^2*vcov (m314e)[3,3]+1^2*vcov (m314e)[4,4]+1^2*1^2*vcov (m314e)[5,5]+2*1*vcov (m314e)[1,3]+2*1*vcov (m314e)[1,4]+2*1*1*vcov (m314e)[1,5]+2*1*1*vcov (m314e)[3,4]+2*1*1^2*vcov (m314e)[3,5]+2*1*1^2*vcov (m314e)[4,5]))
  , c (coef.m314f[1:7,2], rep (NA, 2+2), coef.m314f[8:10,2]
       , sqrt (vcov (m314f)[1,1])
       , sqrt (vcov (m314f)[1,1]+1^2*vcov (m314f)[4,4]+2*1*vcov (m314f)[1,4])
       , sqrt (vcov (m314f)[1,1]+1^2*vcov (m314f)[3,3]+2*1*vcov (m314f)[1,3])
       , sqrt (vcov (m314f)[1,1]+1^2*vcov (m314f)[3,3]+1^2*vcov (m314f)[4,4]+1^2*1^2*vcov (m314f)[5,5]+2*1*vcov (m314f)[1,3]+2*1*vcov (m314f)[1,4]+2*1*1*vcov (m314f)[1,5]+2*1*1*vcov (m314f)[3,4]+2*1*1^2*vcov (m314f)[3,5]+2*1*1^2*vcov (m314f)[4,5]))
  , rep (NA, 18)
  , c (NA, coef.m324a[1,2], rep (NA, 5), coef.m324a[2,2], rep (NA, 1+2), coef.m324a[3,2], rep (NA, 2+4))
  , c (coef.m324e[c (1:2,4),2], rep (NA, 4), coef.m324e[c (3,5),2], rep (NA, 2), coef.m324e[6,2], rep (NA, 2)
       , sqrt (vcov (m324e)[1,1])
       , sqrt (vcov (m324e)[1,1]+1^2*vcov (m324e)[5,5]+2*1*vcov (m324e)[1,5])
       , NA
       , sqrt (vcov (m324e)[1,1]+1^2*vcov (m324e)[4,4]+2*1*vcov (m324e)[1,4]))
  , c (coef.m324f[c (1:2,4),2], rep (NA, 4), coef.m324f[c (3,5),2], rep (NA, 2), coef.m324f[6:8,2]
       , sqrt (vcov (m324f)[1,1])
       , sqrt (vcov (m324f)[1,1]+1^2*vcov (m324f)[5,5]+2*1*vcov (m324f)[1,5])
       , NA
       , sqrt (vcov (m324f)[1,1]+1^2*vcov (m324f)[4,4]+2*1*vcov (m324f)[1,4]))
  , rep (NA, 18)
  , c (coef.m314g[1:7,2], rep (NA, 2+2), coef.m314g[8,2], rep (NA, 2)
       , sqrt (vcov (m314g)[1,1])
       , sqrt (vcov (m314g)[1,1]+1^2*vcov (m314g)[4,4]+2*1*vcov (m314g)[1,4])
       , sqrt (vcov (m314g)[1,1]+1^2*vcov (m314g)[3,3]+2*1*vcov (m314g)[1,3])
       , sqrt (vcov (m314g)[1,1]+1^2*vcov (m314g)[3,3]+1^2*vcov (m314g)[4,4]+1^2*1^2*vcov (m314g)[5,5]+2*1*vcov (m314g)[1,3]+2*1*vcov (m314g)[1,4]+2*1*1*vcov (m314g)[1,5]+2*1*1*vcov (m314g)[3,4]+2*1*1^2*vcov (m314g)[3,5]+2*1*1^2*vcov (m314g)[4,5]))
  , c (coef.m324g[c (1:2,4),2], rep (NA, 4), coef.m324g[c (3,5),2], rep (NA, 2), coef.m324g[6,2], rep (NA, 2)
       , sqrt (vcov (m324g)[1,1])
       , sqrt (vcov (m324g)[1,1]+1^2*vcov (m324g)[5,5]+2*1*vcov (m324g)[1,5])
       , NA
       , sqrt (vcov (m324g)[1,1]+1^2*vcov (m324g)[4,4]+2*1*vcov (m324g)[1,4]))
  , rep (NA, 18)
  , c (coef.m314i[1:7,2], rep (NA, 2+2), coef.m314i[8,2], rep (NA, 2)
       , sqrt (vcov (m314i)[1,1])
       , sqrt (vcov (m314i)[1,1]+1^2*vcov (m314i)[4,4]+2*1*vcov (m314i)[1,4])
       , sqrt (vcov (m314i)[1,1]+1^2*vcov (m314i)[3,3]+2*1*vcov (m314i)[1,3])
       , sqrt (vcov (m314i)[1,1]+1^2*vcov (m314i)[3,3]+1^2*vcov (m314i)[4,4]+1^2*1^2*vcov (m314i)[5,5]+2*1*vcov (m314i)[1,3]+2*1*vcov (m314i)[1,4]+2*1*1*vcov (m314i)[1,5]+2*1*1*vcov (m314i)[3,4]+2*1*1^2*vcov (m314i)[3,5]+2*1*1^2*vcov (m314i)[4,5]))
  , c (coef.m324i[c (1:2,4),2], rep (NA, 4), coef.m324i[c (3,5:8),2], rep (NA, 2)
       , sqrt (vcov (m324i)[1,1])
       , sqrt (vcov (m324i)[1,1]+1^2*vcov (m324i)[5,5]+2*1*vcov (m324i)[1,5])
       , NA
       , sqrt (vcov (m324i)[1,1]+1^2*vcov (m324i)[4,4]+2*1*vcov (m324i)[1,4]))))

odd <- seq (1, nrow (coefSpecification09a)*2, by=2); even <- seq (2, nrow (coefSpecification09a)*2, by=2)
(coefSpecification09tab <- data.frame (rbind (coefSpecification09a, seSpecification09a))) ## warnings reported. Don't worry
rownames (coefSpecification09tab) <- c (odd, even)
coefSpecification09tab <- coefSpecification09tab[order (as.numeric (rownames (coefSpecification09tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m304a$df[1]+sum.m304a$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m314a$df[1]+sum.m314a$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m314c$df[1]+sum.m314c$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m314e$df[1]+sum.m314e$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m314f$df[1]+sum.m314f$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m324a$df[1]+sum.m324a$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m324e$df[1]+sum.m324e$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m324f$df[1]+sum.m324f$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m314g$df[1]+sum.m314g$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m324g$df[1]+sum.m324g$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m314i$df[1]+sum.m314i$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))
  , c (sum.m324i$df[1]+sum.m324i$df[2], length (unique (maddMain$idRegime)), length (unique (maddMain$country)))))

(Fit00 <- cbind (
  c (AIC (m304a), BIC (m304a))
  , c (AIC (m314a), BIC (m314a))
  , c (AIC (m314c), BIC (m314c))
  , c (AIC (m314e), BIC (m314e))
  , c (AIC (m314f), BIC (m314f))
  , c (AIC (m324a), BIC (m324a))
  , c (AIC (m324e), BIC (m324e))
  , c (AIC (m324f), BIC (m324f))
  , c (AIC (m314g), BIC (m314g))
  , c (AIC (m324g), BIC (m324g))
  , c (AIC (m314i), BIC (m314i))
  , c (AIC (m324i), BIC (m324i))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$} (linear predictor)} \\\\ \\midrule \n")

aic <- paste ("\\midrule AIC & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[1,12],0)), "} \\\\ \n")
bic <- paste ("BIC & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Fit00[2,12],0)), "} \\\\ \n")
n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , aic, bic, n.obs#, n.reg, n.ctry
)
print (xtable (cbind (rows, parSE (coefSpecification09tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Survival models (3): Probit link ($+$ unit means)"
               , label="T:rSpecificationProbit02")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (4.9.2) Figure A20

# (4.9.2.1) Marginal effect of growth (t-1) on Linear predictor:

# creating the dataset for the plots
dPlotSpecification09g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotSpecification09g) <- "dataset"
dPlotSpecification09g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotSpecification09g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotSpecification09g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotSpecification09g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotSpecification09g$estimate <- c (coefSpecification09tab[c (29, 33, 31, 35),5], coefSpecification09tab[c (29, 33, 31, 35),9]
                                     , coefSpecification09tab[c (29, 33, 31, 35),6], coefSpecification09tab[c (29, 33, 31, 35),10]
                                     , coefSpecification09tab[c (29, 33, 31, 35),12], coefSpecification09tab[c (29, 33, 31, 35),13]
                                     , coefSpecification09tab[c (29, 33, 31, 35),15], coefSpecification09tab[c (29, 33, 31, 35),16])
dPlotSpecification09g$se <- c (coefSpecification09tab[c (29, 33, 31, 35)+1,5], coefSpecification09tab[c (29, 33, 31, 35)+1,9]
                               , coefSpecification09tab[c (29, 33, 31, 35)+1,6], coefSpecification09tab[c (29, 33, 31, 35)+1,10]
                               , coefSpecification09tab[c (29, 33, 31, 35)+1,12], coefSpecification09tab[c (29, 33, 31, 35)+1,13]
                               , coefSpecification09tab[c (29, 33, 31, 35)+1,15], coefSpecification09tab[c (29, 33, 31, 35)+1,16])
dPlotSpecification09g$ciLow <- with (dPlotSpecification09g, estimate + se*qt (0.025, df=n))
dPlotSpecification09g$ciHigh <- with (dPlotSpecification09g, estimate + se*qt (0.975, df=n))
dPlotSpecification09g <- dPlotSpecification09g[!is.na (dPlotSpecification09g$estimate),]
dPlotSpecification09g$effect <- factor (dPlotSpecification09g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (4.9.2.2) Marginal effect of election (t) on Linear predictor:
dPlotSpecification09el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotSpecification09el) <- "dataset"
dPlotSpecification09el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotSpecification09el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotSpecification09el$growth <- rep (seq (min (maddMain$madddGDPHead_lag), max (maddMain$madddGDPHead_lag), length.out=m), 3)
dPlotSpecification09el$estimate <- with (dPlotSpecification09el, ifelse (
  elType=="actual elections\n(closed)", coef.m314e[2,1]+coef.m314e[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", coef.m314e[2,1]+coef.m314e[7,1]+(coef.m314e[3,1]+coef.m314e[5,1])*growth, coef.m324e[2,1]+coef.m324e[4,1]*growth)))
dPlotSpecification09el$se <- with (dPlotSpecification09el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m314e)[2,2] + (growth^2)*vcov (m314e)[3,3] + (2*growth)*vcov (m314e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m314e)[2,2] + (growth^2)*vcov (m314e)[3,3] + (1^2)*vcov (m314e)[7,7] + (growth^2)*(1^2)*vcov (m314e)[5,5] + (2*growth)*vcov (m314e)[2,3] + (2*1)*vcov (m314e)[2,7] + (2*growth*1)*vcov (m314e)[2,5] + (2*growth*1)*vcov (m314e)[3,7] + (2*1*growth^2)*vcov (m314e)[3,5] + (2*growth*1^2)*vcov (m314e)[7,5]), sqrt (vcov (m324e)[2,2] + (growth^2)*vcov (m324e)[4,4] + (2*growth)*vcov (m324e)[2,4]))))
dPlotSpecification09el$ciLow <- with (dPlotSpecification09el, estimate + se*qt (0.025, df=n))
dPlotSpecification09el$ciHigh <- with (dPlotSpecification09el, estimate + se*qt (0.975, df=n))
dPlotSpecification09el <- dPlotSpecification09el[abs (dPlotSpecification09el$growth) <= h.lim,]

# (4.9.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectSpecificationProbitMean01 <- ggplot (dPlotSpecification09g[dPlotSpecification09g$elType=="competitive\n& executive",]
                                             , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non linear predictor")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectSpecificationProbitMean02 <- ggplot (dPlotSpecification09g[dPlotSpecification09g$controls=="no controls",]
                                             , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non linear predictor")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthSpecificationProbitMean <- ggplot (maddMain[abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectSpecificationProbitMean03 <- ggplot (dPlotSpecification09el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthSpecificationProbitMean), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non linear predictor"))

# (4.9.2.4) Exporting the plots
png ("Figures/fig_rSpecificationProbitMean01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecificationProbitMean01
dev.off ()
png ("Figures/fig_rSpecificationProbitMean02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecificationProbitMean02
dev.off ()
png ("Figures/fig_rSpecificationProbitMean03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectSpecificationProbitMean03
dev.off ()


## (4.10) Table A28: Country FEs
(coefSpecification10a <- cbind (
  c (sum.m305a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m315a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m315c$coef[1:3,1], rep (NA, 6+5), sum.m315c$coef[1,1], sum.m315c$coef[1,1], sum.m315c$coef[1,1]+sum.m315c$coef[3,1], sum.m315c$coef[1,1]+sum.m315c$coef[3,1])
  , c (sum.m315e$coef[1:7,1], rep (NA, 2+5), sum.m315e$coef[1,1], sum.m315e$coef[1,1]+sum.m315e$coef[4,1], sum.m315e$coef[1,1]+sum.m315e$coef[3,1], sum.m315e$coef[1,1]+sum.m315e$coef[3,1]+sum.m315e$coef[4,1]+sum.m315e$coef[5,1])
  , c (sum.m315f$coef[1:7,1], rep (NA, 2+2), sum.m315f$coef[8:10,1], sum.m315f$coef[1,1], sum.m315f$coef[1,1]+sum.m315f$coef[4,1], sum.m315f$coef[1,1]+sum.m315f$coef[3,1], sum.m315f$coef[1,1]+sum.m315f$coef[3,1]+sum.m315f$coef[4,1]+sum.m315f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m325a$coef[1,1], rep (NA, 5), sum.m325a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m325e$coef[c (1:2,4),1], rep (NA, 4), sum.m325e$coef[c (3,5),1], rep (NA, 5), sum.m325e$coef[1,1], sum.m325e$coef[1,1]+sum.m325e$coef[5,1], NA, sum.m325e$coef[1,1]+sum.m325e$coef[4,1])
  , c (sum.m325f$coef[c (1:2,4),1], rep (NA, 4), sum.m325f$coef[c (3,5),1], rep (NA, 2), sum.m325f$coef[6:8,1], sum.m325f$coef[1,1], sum.m325f$coef[1,1]+sum.m325f$coef[5,1], NA, sum.m325f$coef[1,1]+sum.m325f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m315g$coef[1:7,1], rep (NA, 2+5), sum.m315g$coef[1,1], sum.m315g$coef[1,1]+sum.m315g$coef[4,1], sum.m315g$coef[1,1]+sum.m315g$coef[3,1], sum.m315g$coef[1,1]+sum.m315g$coef[3,1]+sum.m315g$coef[4,1]+sum.m315g$coef[5,1])
  , c (sum.m325g$coef[c (1:2,4),1], rep (NA, 4), sum.m325g$coef[c (3,5),1], rep (NA, 5), sum.m325g$coef[1,1], sum.m325g$coef[1,1]+sum.m325g$coef[5,1], NA, sum.m325g$coef[1,1]+sum.m325g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m315i$coef[1:7,1], rep (NA, 2+5), sum.m315i$coef[1,1], sum.m315i$coef[1,1]+sum.m315i$coef[4,1], sum.m315i$coef[1,1]+sum.m315i$coef[3,1], sum.m315i$coef[1,1]+sum.m315i$coef[3,1]+sum.m315i$coef[4,1]+sum.m315i$coef[5,1])
  , c (sum.m325i$coef[c (1:2,4),1], rep (NA, 4), sum.m325i$coef[c (3,5:7),1], rep (NA, 3), sum.m325i$coef[1,1], sum.m325i$coef[1,1]+sum.m325i$coef[5,1], NA, sum.m325i$coef[1,1]+sum.m325i$coef[4,1])))
(seSpecification10a <- cbind (
  c (sum.m305a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m315a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m315c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m315c)[1,1])
       , sqrt (vcov (m315c)[1,1])
       , sqrt (vcov (m315c)[1,1]+1^2*vcov (m315c)[3,3]+2*1*vcov (m315c)[1,3])
       , sqrt (vcov (m315c)[1,1]+1^2*vcov (m315c)[3,3]+2*1*vcov (m315c)[1,3]))
  , c (sum.m315e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m315e)[1,1])
       , sqrt (vcov (m315e)[1,1]+1^2*vcov (m315e)[4,4]+2*1*vcov (m315e)[1,4])
       , sqrt (vcov (m315e)[1,1]+1^2*vcov (m315e)[3,3]+2*1*vcov (m315e)[1,3])
       , sqrt (vcov (m315e)[1,1]+1^2*vcov (m315e)[3,3]+1^2*vcov (m315e)[4,4]+1^2*1^2*vcov (m315e)[5,5]+2*1*vcov (m315e)[1,3]+2*1*vcov (m315e)[1,4]+2*1*1*vcov (m315e)[1,5]+2*1*1*vcov (m315e)[3,4]+2*1*1^2*vcov (m315e)[3,5]+2*1*1^2*vcov (m315e)[4,5]))
  , c (sum.m315f$coef[1:7,2], rep (NA, 2+2), sum.m315f$coef[8:10,2]
       , sqrt (vcov (m315f)[1,1])
       , sqrt (vcov (m315f)[1,1]+1^2*vcov (m315f)[4,4]+2*1*vcov (m315f)[1,4])
       , sqrt (vcov (m315f)[1,1]+1^2*vcov (m315f)[3,3]+2*1*vcov (m315f)[1,3])
       , sqrt (vcov (m315f)[1,1]+1^2*vcov (m315f)[3,3]+1^2*vcov (m315f)[4,4]+1^2*1^2*vcov (m315f)[5,5]+2*1*vcov (m315f)[1,3]+2*1*vcov (m315f)[1,4]+2*1*1*vcov (m315f)[1,5]+2*1*1*vcov (m315f)[3,4]+2*1*1^2*vcov (m315f)[3,5]+2*1*1^2*vcov (m315f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m325a$coef[1,2], rep (NA, 5), sum.m325a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m325e$coef[c (1:2,4),2], rep (NA, 4), sum.m325e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m325e)[1,1])
       , sqrt (vcov (m325e)[1,1]+1^2*vcov (m325e)[5,5]+2*1*vcov (m325e)[1,5])
       , NA
       , sqrt (vcov (m325e)[1,1]+1^2*vcov (m325e)[4,4]+2*1*vcov (m325e)[1,4]))
  , c (sum.m325f$coef[c (1:2,4),2], rep (NA, 4), sum.m325f$coef[c (3,5),2], rep (NA, 2), sum.m325f$coef[6:8,2]
       , sqrt (vcov (m325f)[1,1])
       , sqrt (vcov (m325f)[1,1]+1^2*vcov (m325f)[5,5]+2*1*vcov (m325f)[1,5])
       , NA
       , sqrt (vcov (m325f)[1,1]+1^2*vcov (m325f)[4,4]+2*1*vcov (m325f)[1,4]))
  , rep (NA, 18)
  , c (sum.m315g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m315g)[1,1])
       , sqrt (vcov (m315g)[1,1]+1^2*vcov (m315g)[4,4]+2*1*vcov (m315g)[1,4])
       , sqrt (vcov (m315g)[1,1]+1^2*vcov (m315g)[3,3]+2*1*vcov (m315g)[1,3])
       , sqrt (vcov (m315g)[1,1]+1^2*vcov (m315g)[3,3]+1^2*vcov (m315g)[4,4]+1^2*1^2*vcov (m315g)[5,5]+2*1*vcov (m315g)[1,3]+2*1*vcov (m315g)[1,4]+2*1*1*vcov (m315g)[1,5]+2*1*1*vcov (m315g)[3,4]+2*1*1^2*vcov (m315g)[3,5]+2*1*1^2*vcov (m315g)[4,5]))
  , c (sum.m325g$coef[c (1:2,4),2], rep (NA, 4), sum.m325g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m325g)[1,1])
       , sqrt (vcov (m325g)[1,1]+1^2*vcov (m325g)[5,5]+2*1*vcov (m325g)[1,5])
       , NA
       , sqrt (vcov (m325g)[1,1]+1^2*vcov (m325g)[4,4]+2*1*vcov (m325g)[1,4]))
  , rep (NA, 18)
  , c (sum.m315i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m315i)[1,1])
       , sqrt (vcov (m315i)[1,1]+1^2*vcov (m315i)[4,4]+2*1*vcov (m315i)[1,4])
       , sqrt (vcov (m315i)[1,1]+1^2*vcov (m315i)[3,3]+2*1*vcov (m315i)[1,3])
       , sqrt (vcov (m315i)[1,1]+1^2*vcov (m315i)[3,3]+1^2*vcov (m315i)[4,4]+1^2*1^2*vcov (m315i)[5,5]+2*1*vcov (m315i)[1,3]+2*1*vcov (m315i)[1,4]+2*1*1*vcov (m315i)[1,5]+2*1*1*vcov (m315i)[3,4]+2*1*1^2*vcov (m315i)[3,5]+2*1*1^2*vcov (m315i)[4,5]))
  , c (sum.m325i$coef[c (1:2,4),2], rep (NA, 4), sum.m325i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m325i)[1,1])
       , sqrt (vcov (m325i)[1,1]+1^2*vcov (m325i)[5,5]+2*1*vcov (m325i)[1,5])
       , NA
       , sqrt (vcov (m325i)[1,1]+1^2*vcov (m325i)[4,4]+2*1*vcov (m325i)[1,4]))))

odd <- seq (1, nrow (coefSpecification10a)*2, by=2); even <- seq (2, nrow (coefSpecification10a)*2, by=2)
(coefSpecification10tab <- data.frame (rbind (coefSpecification10a, seSpecification10a))) ## warnings reported. Don't worry
rownames (coefSpecification10tab) <- c (odd, even)
coefSpecification10tab <- coefSpecification10tab[order (as.numeric (rownames (coefSpecification10tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m305a$N, length (unique (sum.m305a$fe$country)), length (unique (sum.m305a$fe$year.f)))
  , c (sum.m315a$N, length (unique (sum.m315a$fe$country)), length (unique (sum.m315a$fe$year.f)))
  , c (sum.m315c$N, length (unique (sum.m315c$fe$country)), length (unique (sum.m315c$fe$year.f)))
  , c (sum.m315e$N, length (unique (sum.m315e$fe$country)), length (unique (sum.m315e$fe$year.f)))
  , c (sum.m315f$N, length (unique (sum.m315f$fe$country)), length (unique (sum.m315f$fe$year.f)))
  , c (sum.m325a$N, length (unique (sum.m325a$fe$country)), length (unique (sum.m325a$fe$year.f)))
  , c (sum.m325e$N, length (unique (sum.m325e$fe$country)), length (unique (sum.m325e$fe$year.f)))
  , c (sum.m325f$N, length (unique (sum.m325f$fe$country)), length (unique (sum.m325f$fe$year.f)))
  , c (sum.m315g$N, length (unique (sum.m315g$fe$country)), length (unique (sum.m315g$fe$year.f)))
  , c (sum.m325g$N, length (unique (sum.m325g$fe$country)), length (unique (sum.m325g$fe$year.f)))
  , c (sum.m315i$N, length (unique (sum.m315i$fe$country)), length (unique (sum.m315i$fe$year.f)))
  , c (sum.m325i$N, length (unique (sum.m325i$fe$country)), length (unique (sum.m325i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.ctry)
print (xtable (cbind (rows, parSE (coefSpecification10tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Country fixed effects"
               , label="T:rSpecificationFE")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (4.10.2) Figure A21

# (4.10.2.1) Marginal effect of growth (t-1) on Pr (breakdown t):

# creating the dataset for the plots
dPlotSpecification10g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotSpecification10g) <- "dataset"
dPlotSpecification10g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotSpecification10g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotSpecification10g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotSpecification10g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotSpecification10g$estimate <- c (coefSpecification10tab[c (29, 33, 31, 35),5], coefSpecification10tab[c (29, 33, 31, 35),9]
                                     , coefSpecification10tab[c (29, 33, 31, 35),6], coefSpecification10tab[c (29, 33, 31, 35),10]
                                     , coefSpecification10tab[c (29, 33, 31, 35),12], coefSpecification10tab[c (29, 33, 31, 35),13]
                                     , coefSpecification10tab[c (29, 33, 31, 35),15], coefSpecification10tab[c (29, 33, 31, 35),16])
dPlotSpecification10g$se <- c (coefSpecification10tab[c (29, 33, 31, 35)+1,5], coefSpecification10tab[c (29, 33, 31, 35)+1,9]
                               , coefSpecification10tab[c (29, 33, 31, 35)+1,6], coefSpecification10tab[c (29, 33, 31, 35)+1,10]
                               , coefSpecification10tab[c (29, 33, 31, 35)+1,12], coefSpecification10tab[c (29, 33, 31, 35)+1,13]
                               , coefSpecification10tab[c (29, 33, 31, 35)+1,15], coefSpecification10tab[c (29, 33, 31, 35)+1,16])
dPlotSpecification10g$ciLow <- with (dPlotSpecification10g, estimate + se*qt (0.025, df=n))
dPlotSpecification10g$ciHigh <- with (dPlotSpecification10g, estimate + se*qt (0.975, df=n))
dPlotSpecification10g <- dPlotSpecification10g[!is.na (dPlotSpecification10g$estimate),]
dPlotSpecification10g$effect <- factor (dPlotSpecification10g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (4.10.2.2) Marginal effect of election (t) on Pr (breakdown t):
dPlotSpecification10el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotSpecification10el) <- "dataset"
dPlotSpecification10el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotSpecification10el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotSpecification10el$growth <- rep (seq (min (maddMain$madddGDPHead_lag), max (maddMain$madddGDPHead_lag), length.out=m), 3)
dPlotSpecification10el$estimate <- with (dPlotSpecification10el, ifelse (
  elType=="actual elections\n(closed)", sum.m315e$coef[2,1]+sum.m315e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m315e$coef[2,1]+sum.m315e$coef[7,1]+(sum.m315e$coef[3,1]+sum.m315e$coef[5,1])*growth, sum.m325e$coef[2,1]+sum.m325e$coef[4,1]*growth)))
dPlotSpecification10el$se <- with (dPlotSpecification10el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m315e)[2,2] + (growth^2)*vcov (m315e)[3,3] + (2*growth)*vcov (m315e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m315e)[2,2] + (growth^2)*vcov (m315e)[3,3] + (1^2)*vcov (m315e)[7,7] + (growth^2)*(1^2)*vcov (m315e)[5,5] + (2*growth)*vcov (m315e)[2,3] + (2*1)*vcov (m315e)[2,7] + (2*growth*1)*vcov (m315e)[2,5] + (2*growth*1)*vcov (m315e)[3,7] + (2*1*growth^2)*vcov (m315e)[3,5] + (2*growth*1^2)*vcov (m315e)[7,5]), sqrt (vcov (m325e)[2,2] + (growth^2)*vcov (m325e)[4,4] + (2*growth)*vcov (m325e)[2,4]))))
dPlotSpecification10el$ciLow <- with (dPlotSpecification10el, estimate + se*qt (0.025, df=n))
dPlotSpecification10el$ciHigh <- with (dPlotSpecification10el, estimate + se*qt (0.975, df=n))
dPlotSpecification10el <- dPlotSpecification10el[abs (dPlotSpecification10el$growth) <= h.lim,]

# (4.10.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectSpecification01 <- ggplot (dPlotSpecification10g[dPlotSpecification10g$elType=="competitive\n& executive",]
                                   , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectSpecification02 <- ggplot (dPlotSpecification10g[dPlotSpecification10g$controls=="no controls",]
                                   , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthSpecification <- ggplot (maddMain[abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectSpecification03 <- ggplot (dPlotSpecification10el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthSpecification), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# (4.10.2.4) Exporting the plots
png ("Figures/fig_rSpecificationFE01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecification01
dev.off ()
png ("Figures/fig_rSpecificationFE02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSpecification02
dev.off ()
png ("Figures/fig_rSpecificationFE03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectSpecification03
dev.off ()





### (5) Alternative measures of regime type: Tables A29-A31 and Figures A22-A24

## (5.1) Table A29: Adding indirect regimes and oligarchies
(coefRegime01a <- cbind (
  c (sum.m401a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m411a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m411c$coef[1:3,1], rep (NA, 6+5), sum.m411c$coef[1,1], sum.m411c$coef[1,1], sum.m411c$coef[1,1]+sum.m411c$coef[3,1], sum.m411c$coef[1,1]+sum.m411c$coef[3,1])
  , c (sum.m411e$coef[1:7,1], rep (NA, 2+5), sum.m411e$coef[1,1], sum.m411e$coef[1,1]+sum.m411e$coef[4,1], sum.m411e$coef[1,1]+sum.m411e$coef[3,1], sum.m411e$coef[1,1]+sum.m411e$coef[3,1]+sum.m411e$coef[4,1]+sum.m411e$coef[5,1])
  , c (sum.m411f$coef[1:7,1], rep (NA, 2+2), sum.m411f$coef[8:10,1], sum.m411f$coef[1,1], sum.m411f$coef[1,1]+sum.m411f$coef[4,1], sum.m411f$coef[1,1]+sum.m411f$coef[3,1], sum.m411f$coef[1,1]+sum.m411f$coef[3,1]+sum.m411f$coef[4,1]+sum.m411f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m421a$coef[1,1], rep (NA, 5), sum.m421a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m421e$coef[c (1:2,4),1], rep (NA, 4), sum.m421e$coef[c (3,5),1], rep (NA, 5), sum.m421e$coef[1,1], sum.m421e$coef[1,1]+sum.m421e$coef[5,1], NA, sum.m421e$coef[1,1]+sum.m421e$coef[4,1])
  , c (sum.m421f$coef[c (1:2,4),1], rep (NA, 4), sum.m421f$coef[c (3,5),1], rep (NA, 2), sum.m421f$coef[6:8,1], sum.m421f$coef[1,1], sum.m421f$coef[1,1]+sum.m421f$coef[5,1], NA, sum.m421f$coef[1,1]+sum.m421f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m411g$coef[1:7,1], rep (NA, 2+5), sum.m411g$coef[1,1], sum.m411g$coef[1,1]+sum.m411g$coef[4,1], sum.m411g$coef[1,1]+sum.m411g$coef[3,1], sum.m411g$coef[1,1]+sum.m411g$coef[3,1]+sum.m411g$coef[4,1]+sum.m411g$coef[5,1])
  , c (sum.m421g$coef[c (1:2,4),1], rep (NA, 4), sum.m421g$coef[c (3,5),1], rep (NA, 5), sum.m421g$coef[1,1], sum.m421g$coef[1,1]+sum.m421g$coef[5,1], NA, sum.m421g$coef[1,1]+sum.m421g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m411i$coef[1:7,1], rep (NA, 2+5), sum.m411i$coef[1,1], sum.m411i$coef[1,1]+sum.m411i$coef[4,1], sum.m411i$coef[1,1]+sum.m411i$coef[3,1], sum.m411i$coef[1,1]+sum.m411i$coef[3,1]+sum.m411i$coef[4,1]+sum.m411i$coef[5,1])
  , c (sum.m421i$coef[c (1:2,4),1], rep (NA, 4), sum.m421i$coef[c (3,5:7),1], rep (NA, 3), sum.m421i$coef[1,1], sum.m421i$coef[1,1]+sum.m421i$coef[5,1], NA, sum.m421i$coef[1,1]+sum.m421i$coef[4,1])))
(seRegime01a <- cbind (
  c (sum.m401a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m411a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m411c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m411c)[1,1])
       , sqrt (vcov (m411c)[1,1])
       , sqrt (vcov (m411c)[1,1]+1^2*vcov (m411c)[3,3]+2*1*vcov (m411c)[1,3])
       , sqrt (vcov (m411c)[1,1]+1^2*vcov (m411c)[3,3]+2*1*vcov (m411c)[1,3]))
  , c (sum.m411e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m411e)[1,1])
       , sqrt (vcov (m411e)[1,1]+1^2*vcov (m411e)[4,4]+2*1*vcov (m411e)[1,4])
       , sqrt (vcov (m411e)[1,1]+1^2*vcov (m411e)[3,3]+2*1*vcov (m411e)[1,3])
       , sqrt (vcov (m411e)[1,1]+1^2*vcov (m411e)[3,3]+1^2*vcov (m411e)[4,4]+1^2*1^2*vcov (m411e)[5,5]+2*1*vcov (m411e)[1,3]+2*1*vcov (m411e)[1,4]+2*1*1*vcov (m411e)[1,5]+2*1*1*vcov (m411e)[3,4]+2*1*1^2*vcov (m411e)[3,5]+2*1*1^2*vcov (m411e)[4,5]))
  , c (sum.m411f$coef[1:7,2], rep (NA, 2+2), sum.m411f$coef[8:10,2]
       , sqrt (vcov (m411f)[1,1])
       , sqrt (vcov (m411f)[1,1]+1^2*vcov (m411f)[4,4]+2*1*vcov (m411f)[1,4])
       , sqrt (vcov (m411f)[1,1]+1^2*vcov (m411f)[3,3]+2*1*vcov (m411f)[1,3])
       , sqrt (vcov (m411f)[1,1]+1^2*vcov (m411f)[3,3]+1^2*vcov (m411f)[4,4]+1^2*1^2*vcov (m411f)[5,5]+2*1*vcov (m411f)[1,3]+2*1*vcov (m411f)[1,4]+2*1*1*vcov (m411f)[1,5]+2*1*1*vcov (m411f)[3,4]+2*1*1^2*vcov (m411f)[3,5]+2*1*1^2*vcov (m411f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m421a$coef[1,2], rep (NA, 5), sum.m421a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m421e$coef[c (1:2,4),2], rep (NA, 4), sum.m421e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m421e)[1,1])
       , sqrt (vcov (m421e)[1,1]+1^2*vcov (m421e)[5,5]+2*1*vcov (m421e)[1,5])
       , NA
       , sqrt (vcov (m421e)[1,1]+1^2*vcov (m421e)[4,4]+2*1*vcov (m421e)[1,4]))
  , c (sum.m421f$coef[c (1:2,4),2], rep (NA, 4), sum.m421f$coef[c (3,5),2], rep (NA, 2), sum.m421f$coef[6:8,2]
       , sqrt (vcov (m421f)[1,1])
       , sqrt (vcov (m421f)[1,1]+1^2*vcov (m421f)[5,5]+2*1*vcov (m421f)[1,5])
       , NA
       , sqrt (vcov (m421f)[1,1]+1^2*vcov (m421f)[4,4]+2*1*vcov (m421f)[1,4]))
  , rep (NA, 18)
  , c (sum.m411g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m411g)[1,1])
       , sqrt (vcov (m411g)[1,1]+1^2*vcov (m411g)[4,4]+2*1*vcov (m411g)[1,4])
       , sqrt (vcov (m411g)[1,1]+1^2*vcov (m411g)[3,3]+2*1*vcov (m411g)[1,3])
       , sqrt (vcov (m411g)[1,1]+1^2*vcov (m411g)[3,3]+1^2*vcov (m411g)[4,4]+1^2*1^2*vcov (m411g)[5,5]+2*1*vcov (m411g)[1,3]+2*1*vcov (m411g)[1,4]+2*1*1*vcov (m411g)[1,5]+2*1*1*vcov (m411g)[3,4]+2*1*1^2*vcov (m411g)[3,5]+2*1*1^2*vcov (m411g)[4,5]))
  , c (sum.m421g$coef[c (1:2,4),2], rep (NA, 4), sum.m421g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m421g)[1,1])
       , sqrt (vcov (m421g)[1,1]+1^2*vcov (m421g)[5,5]+2*1*vcov (m421g)[1,5])
       , NA
       , sqrt (vcov (m421g)[1,1]+1^2*vcov (m421g)[4,4]+2*1*vcov (m421g)[1,4]))
  , rep (NA, 18)
  , c (sum.m411i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m411i)[1,1])
       , sqrt (vcov (m411i)[1,1]+1^2*vcov (m411i)[4,4]+2*1*vcov (m411i)[1,4])
       , sqrt (vcov (m411i)[1,1]+1^2*vcov (m411i)[3,3]+2*1*vcov (m411i)[1,3])
       , sqrt (vcov (m411i)[1,1]+1^2*vcov (m411i)[3,3]+1^2*vcov (m411i)[4,4]+1^2*1^2*vcov (m411i)[5,5]+2*1*vcov (m411i)[1,3]+2*1*vcov (m411i)[1,4]+2*1*1*vcov (m411i)[1,5]+2*1*1*vcov (m411i)[3,4]+2*1*1^2*vcov (m411i)[3,5]+2*1*1^2*vcov (m411i)[4,5]))
  , c (sum.m421i$coef[c (1:2,4),2], rep (NA, 4), sum.m421i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m421i)[1,1])
       , sqrt (vcov (m421i)[1,1]+1^2*vcov (m421i)[5,5]+2*1*vcov (m421i)[1,5])
       , NA
       , sqrt (vcov (m421i)[1,1]+1^2*vcov (m421i)[4,4]+2*1*vcov (m421i)[1,4]))))

odd <- seq (1, nrow (coefRegime01a)*2, by=2); even <- seq (2, nrow (coefRegime01a)*2, by=2)
(coefRegime01tab <- data.frame (rbind (coefRegime01a, seRegime01a))) ## warnings reported. Don't worry
rownames (coefRegime01tab) <- c (odd, even)
coefRegime01tab <- coefRegime01tab[order (as.numeric (rownames (coefRegime01tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m401a$N, length (unique (sum.m401a$fe$idRegime)), length (unique (maddMain2$country)), length (unique (sum.m401a$fe$year.f)))
  , c (sum.m411a$N, length (unique (sum.m411a$fe$idRegime)), length (unique (maddMain2$country)), length (unique (sum.m411a$fe$year.f)))
  , c (sum.m411c$N, length (unique (sum.m411c$fe$idRegime)), length (unique (maddMain2$country)), length (unique (sum.m411c$fe$year.f)))
  , c (sum.m411e$N, length (unique (sum.m411e$fe$idRegime)), length (unique (maddMain2$country)), length (unique (sum.m411e$fe$year.f)))
  , c (sum.m411f$N, length (unique (sum.m411f$fe$idRegime)), length (unique (maddMain2[!is.na (maddMain2$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m411f$fe$year.f)))
  , c (sum.m421a$N, length (unique (sum.m421a$fe$idRegime)), length (unique (maddMain2$country)), length (unique (sum.m421a$fe$year.f)))
  , c (sum.m421e$N, length (unique (sum.m421e$fe$idRegime)), length (unique (maddMain2$country)), length (unique (sum.m421e$fe$year.f)))
  , c (sum.m421f$N, length (unique (sum.m421f$fe$idRegime)), length (unique (maddMain2[!is.na (maddMain2$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m421f$fe$year.f)))
  , c (sum.m411g$N, length (unique (sum.m411g$fe$idRegime)), length (unique (maddMain2$country)), length (unique (sum.m411g$fe$year.f)))
  , c (sum.m421g$N, length (unique (sum.m421g$fe$idRegime)), length (unique (maddMain2$country)), length (unique (sum.m421g$fe$year.f)))
  , c (sum.m411i$N, length (unique (sum.m411i$fe$idRegime)), length (unique (maddMain2$country)), length (unique (sum.m411i$fe$year.f)))
  , c (sum.m421i$N, length (unique (sum.m421i$fe$idRegime)), length (unique (maddMain2$country)), length (unique (sum.m421i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefRegime01tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Alternative measures of regime type (1): Adding indirect regimes and oligarchies"
               , label="T:rRegimeOther")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (5.1.2) Figure A22

# (5.1.2.1) Marginal effect of growth (t-1) on Pr (breakdown t):

# creating the dataset for the plots
dPlotRegime01g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotRegime01g) <- "dataset"
dPlotRegime01g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotRegime01g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotRegime01g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotRegime01g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotRegime01g$estimate <- c (coefRegime01tab[c (29, 33, 31, 35),5], coefRegime01tab[c (29, 33, 31, 35),9]
                              , coefRegime01tab[c (29, 33, 31, 35),6], coefRegime01tab[c (29, 33, 31, 35),10]
                              , coefRegime01tab[c (29, 33, 31, 35),12], coefRegime01tab[c (29, 33, 31, 35),13]
                              , coefRegime01tab[c (29, 33, 31, 35),15], coefRegime01tab[c (29, 33, 31, 35),16])
dPlotRegime01g$se <- c (coefRegime01tab[c (29, 33, 31, 35)+1,5], coefRegime01tab[c (29, 33, 31, 35)+1,9]
                        , coefRegime01tab[c (29, 33, 31, 35)+1,6], coefRegime01tab[c (29, 33, 31, 35)+1,10]
                        , coefRegime01tab[c (29, 33, 31, 35)+1,12], coefRegime01tab[c (29, 33, 31, 35)+1,13]
                        , coefRegime01tab[c (29, 33, 31, 35)+1,15], coefRegime01tab[c (29, 33, 31, 35)+1,16])
dPlotRegime01g$ciLow <- with (dPlotRegime01g, estimate + se*qt (0.025, df=n))
dPlotRegime01g$ciHigh <- with (dPlotRegime01g, estimate + se*qt (0.975, df=n))
dPlotRegime01g <- dPlotRegime01g[!is.na (dPlotRegime01g$estimate),]
dPlotRegime01g$effect <- factor (dPlotRegime01g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (5.1.2.2) Marginal effect of election (t) on Pr (breakdown t):
dPlotRegime01el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotRegime01el) <- "dataset"
dPlotRegime01el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotRegime01el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotRegime01el$growth <- rep (seq (min (maddMain2$madddGDPHead_lag), max (maddMain2$madddGDPHead_lag), length.out=m), 3)
dPlotRegime01el$estimate <- with (dPlotRegime01el, ifelse (
  elType=="actual elections\n(closed)", sum.m411e$coef[2,1]+sum.m411e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m411e$coef[2,1]+sum.m411e$coef[7,1]+(sum.m411e$coef[3,1]+sum.m411e$coef[5,1])*growth, sum.m421e$coef[2,1]+sum.m421e$coef[4,1]*growth)))
dPlotRegime01el$se <- with (dPlotRegime01el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m411e)[2,2] + (growth^2)*vcov (m411e)[3,3] + (2*growth)*vcov (m411e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m411e)[2,2] + (growth^2)*vcov (m411e)[3,3] + (1^2)*vcov (m411e)[7,7] + (growth^2)*(1^2)*vcov (m411e)[5,5] + (2*growth)*vcov (m411e)[2,3] + (2*1)*vcov (m411e)[2,7] + (2*growth*1)*vcov (m411e)[2,5] + (2*growth*1)*vcov (m411e)[3,7] + (2*1*growth^2)*vcov (m411e)[3,5] + (2*growth*1^2)*vcov (m411e)[7,5]), sqrt (vcov (m421e)[2,2] + (growth^2)*vcov (m421e)[4,4] + (2*growth)*vcov (m421e)[2,4]))))
dPlotRegime01el$ciLow <- with (dPlotRegime01el, estimate + se*qt (0.025, df=n))
dPlotRegime01el$ciHigh <- with (dPlotRegime01el, estimate + se*qt (0.975, df=n))
dPlotRegime01el <- dPlotRegime01el[abs (dPlotRegime01el$growth) <= h.lim,]

# (5.1.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectRegime01 <- ggplot (dPlotRegime01g[dPlotRegime01g$elType=="competitive\n& executive",]
                            , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectRegime02 <- ggplot (dPlotRegime01g[dPlotRegime01g$controls=="no controls",]
                            , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthRegime <- ggplot (maddMain2[abs (maddMain2$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectRegime03 <- ggplot (dPlotRegime01el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthRegime), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# (5.1.2.4) Exporting the plots
png ("Figures/fig_rRegimeOther01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectRegime01
dev.off ()
png ("Figures/fig_rRegimeOther02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectRegime02
dev.off ()
png ("Figures/fig_rRegimeOther03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectRegime03
dev.off ()


## (5.2) Table A30: LIED coding of EARs and closed regimes
(coefRegime02a <- cbind (
  c (sum.m402a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m412a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m412c$coef[1:3,1], rep (NA, 6+5), sum.m412c$coef[1,1], sum.m412c$coef[1,1], sum.m412c$coef[1,1]+sum.m412c$coef[3,1], sum.m412c$coef[1,1]+sum.m412c$coef[3,1])
  , c (sum.m412e$coef[1:7,1], rep (NA, 2+5), sum.m412e$coef[1,1], sum.m412e$coef[1,1]+sum.m412e$coef[4,1], sum.m412e$coef[1,1]+sum.m412e$coef[3,1], sum.m412e$coef[1,1]+sum.m412e$coef[3,1]+sum.m412e$coef[4,1]+sum.m412e$coef[5,1])
  , c (sum.m412f$coef[1:7,1], rep (NA, 2+2), sum.m412f$coef[8:10,1], sum.m412f$coef[1,1], sum.m412f$coef[1,1]+sum.m412f$coef[4,1], sum.m412f$coef[1,1]+sum.m412f$coef[3,1], sum.m412f$coef[1,1]+sum.m412f$coef[3,1]+sum.m412f$coef[4,1]+sum.m412f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m422a$coef[1,1], rep (NA, 5), sum.m422a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m422e$coef[c (1:2,4),1], rep (NA, 4), sum.m422e$coef[c (3,5),1], rep (NA, 5), sum.m422e$coef[1,1], sum.m422e$coef[1,1]+sum.m422e$coef[5,1], NA, sum.m422e$coef[1,1]+sum.m422e$coef[4,1])
  , c (sum.m422f$coef[c (1:2,4),1], rep (NA, 4), sum.m422f$coef[c (3,5),1], rep (NA, 2), sum.m422f$coef[6:8,1], sum.m422f$coef[1,1], sum.m422f$coef[1,1]+sum.m422f$coef[5,1], NA, sum.m422f$coef[1,1]+sum.m422f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m412g$coef[1:7,1], rep (NA, 2+5), sum.m412g$coef[1,1], sum.m412g$coef[1,1]+sum.m412g$coef[4,1], sum.m412g$coef[1,1]+sum.m412g$coef[3,1], sum.m412g$coef[1,1]+sum.m412g$coef[3,1]+sum.m412g$coef[4,1]+sum.m412g$coef[5,1])
  , c (sum.m422g$coef[c (1:2,4),1], rep (NA, 4), sum.m422g$coef[c (3,5),1], rep (NA, 5), sum.m422g$coef[1,1], sum.m422g$coef[1,1]+sum.m422g$coef[5,1], NA, sum.m422g$coef[1,1]+sum.m422g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m412i$coef[1:7,1], rep (NA, 2+5), sum.m412i$coef[1,1], sum.m412i$coef[1,1]+sum.m412i$coef[4,1], sum.m412i$coef[1,1]+sum.m412i$coef[3,1], sum.m412i$coef[1,1]+sum.m412i$coef[3,1]+sum.m412i$coef[4,1]+sum.m412i$coef[5,1])
  , c (sum.m422i$coef[c (1:2,4),1], rep (NA, 4), sum.m422i$coef[c (3,5:7),1], rep (NA, 3), sum.m422i$coef[1,1], sum.m422i$coef[1,1]+sum.m422i$coef[5,1], NA, sum.m422i$coef[1,1]+sum.m422i$coef[4,1])))
(seRegime02a <- cbind (
  c (sum.m402a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m412a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m412c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m412c)[1,1])
       , sqrt (vcov (m412c)[1,1])
       , sqrt (vcov (m412c)[1,1]+1^2*vcov (m412c)[3,3]+2*1*vcov (m412c)[1,3])
       , sqrt (vcov (m412c)[1,1]+1^2*vcov (m412c)[3,3]+2*1*vcov (m412c)[1,3]))
  , c (sum.m412e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m412e)[1,1])
       , sqrt (vcov (m412e)[1,1]+1^2*vcov (m412e)[4,4]+2*1*vcov (m412e)[1,4])
       , sqrt (vcov (m412e)[1,1]+1^2*vcov (m412e)[3,3]+2*1*vcov (m412e)[1,3])
       , sqrt (vcov (m412e)[1,1]+1^2*vcov (m412e)[3,3]+1^2*vcov (m412e)[4,4]+1^2*1^2*vcov (m412e)[5,5]+2*1*vcov (m412e)[1,3]+2*1*vcov (m412e)[1,4]+2*1*1*vcov (m412e)[1,5]+2*1*1*vcov (m412e)[3,4]+2*1*1^2*vcov (m412e)[3,5]+2*1*1^2*vcov (m412e)[4,5]))
  , c (sum.m412f$coef[1:7,2], rep (NA, 2+2), sum.m412f$coef[8:10,2]
       , sqrt (vcov (m412f)[1,1])
       , sqrt (vcov (m412f)[1,1]+1^2*vcov (m412f)[4,4]+2*1*vcov (m412f)[1,4])
       , sqrt (vcov (m412f)[1,1]+1^2*vcov (m412f)[3,3]+2*1*vcov (m412f)[1,3])
       , sqrt (vcov (m412f)[1,1]+1^2*vcov (m412f)[3,3]+1^2*vcov (m412f)[4,4]+1^2*1^2*vcov (m412f)[5,5]+2*1*vcov (m412f)[1,3]+2*1*vcov (m412f)[1,4]+2*1*1*vcov (m412f)[1,5]+2*1*1*vcov (m412f)[3,4]+2*1*1^2*vcov (m412f)[3,5]+2*1*1^2*vcov (m412f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m422a$coef[1,2], rep (NA, 5), sum.m422a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m422e$coef[c (1:2,4),2], rep (NA, 4), sum.m422e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m422e)[1,1])
       , sqrt (vcov (m422e)[1,1]+1^2*vcov (m422e)[5,5]+2*1*vcov (m422e)[1,5])
       , NA
       , sqrt (vcov (m422e)[1,1]+1^2*vcov (m422e)[4,4]+2*1*vcov (m422e)[1,4]))
  , c (sum.m422f$coef[c (1:2,4),2], rep (NA, 4), sum.m422f$coef[c (3,5),2], rep (NA, 2), sum.m422f$coef[6:8,2]
       , sqrt (vcov (m422f)[1,1])
       , sqrt (vcov (m422f)[1,1]+1^2*vcov (m422f)[5,5]+2*1*vcov (m422f)[1,5])
       , NA
       , sqrt (vcov (m422f)[1,1]+1^2*vcov (m422f)[4,4]+2*1*vcov (m422f)[1,4]))
  , rep (NA, 18)
  , c (sum.m412g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m412g)[1,1])
       , sqrt (vcov (m412g)[1,1]+1^2*vcov (m412g)[4,4]+2*1*vcov (m412g)[1,4])
       , sqrt (vcov (m412g)[1,1]+1^2*vcov (m412g)[3,3]+2*1*vcov (m412g)[1,3])
       , sqrt (vcov (m412g)[1,1]+1^2*vcov (m412g)[3,3]+1^2*vcov (m412g)[4,4]+1^2*1^2*vcov (m412g)[5,5]+2*1*vcov (m412g)[1,3]+2*1*vcov (m412g)[1,4]+2*1*1*vcov (m412g)[1,5]+2*1*1*vcov (m412g)[3,4]+2*1*1^2*vcov (m412g)[3,5]+2*1*1^2*vcov (m412g)[4,5]))
  , c (sum.m422g$coef[c (1:2,4),2], rep (NA, 4), sum.m422g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m422g)[1,1])
       , sqrt (vcov (m422g)[1,1]+1^2*vcov (m422g)[5,5]+2*1*vcov (m422g)[1,5])
       , NA
       , sqrt (vcov (m422g)[1,1]+1^2*vcov (m422g)[4,4]+2*1*vcov (m422g)[1,4]))
  , rep (NA, 18)
  , c (sum.m412i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m412i)[1,1])
       , sqrt (vcov (m412i)[1,1]+1^2*vcov (m412i)[4,4]+2*1*vcov (m412i)[1,4])
       , sqrt (vcov (m412i)[1,1]+1^2*vcov (m412i)[3,3]+2*1*vcov (m412i)[1,3])
       , sqrt (vcov (m412i)[1,1]+1^2*vcov (m412i)[3,3]+1^2*vcov (m412i)[4,4]+1^2*1^2*vcov (m412i)[5,5]+2*1*vcov (m412i)[1,3]+2*1*vcov (m412i)[1,4]+2*1*1*vcov (m412i)[1,5]+2*1*1*vcov (m412i)[3,4]+2*1*1^2*vcov (m412i)[3,5]+2*1*1^2*vcov (m412i)[4,5]))
  , c (sum.m422i$coef[c (1:2,4),2], rep (NA, 4), sum.m422i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m422i)[1,1])
       , sqrt (vcov (m422i)[1,1]+1^2*vcov (m422i)[5,5]+2*1*vcov (m422i)[1,5])
       , NA
       , sqrt (vcov (m422i)[1,1]+1^2*vcov (m422i)[4,4]+2*1*vcov (m422i)[1,4]))))

odd <- seq (1, nrow (coefRegime02a)*2, by=2); even <- seq (2, nrow (coefRegime02a)*2, by=2)
(coefRegime02tab <- data.frame (rbind (coefRegime02a, seRegime02a))) ## warnings reported. Don't worry
rownames (coefRegime02tab) <- c (odd, even)
coefRegime02tab <- coefRegime02tab[order (as.numeric (rownames (coefRegime02tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m402a$N, length (unique (sum.m402a$fe$idRegime)), length (unique (maddMain2lied$country)), length (unique (sum.m402a$fe$year.f)))
  , c (sum.m412a$N, length (unique (sum.m412a$fe$idRegime)), length (unique (maddMain2lied$country)), length (unique (sum.m412a$fe$year.f)))
  , c (sum.m412c$N, length (unique (sum.m412c$fe$idRegime)), length (unique (maddMain2lied$country)), length (unique (sum.m412c$fe$year.f)))
  , c (sum.m412e$N, length (unique (sum.m412e$fe$idRegime)), length (unique (maddMain2lied$country)), length (unique (sum.m412e$fe$year.f)))
  , c (sum.m412f$N, length (unique (sum.m412f$fe$idRegime)), length (unique (maddMain2lied[!is.na (maddMain2lied$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m412f$fe$year.f)))
  , c (sum.m422a$N, length (unique (sum.m422a$fe$idRegime)), length (unique (maddMain2lied$country)), length (unique (sum.m422a$fe$year.f)))
  , c (sum.m422e$N, length (unique (sum.m422e$fe$idRegime)), length (unique (maddMain2lied$country)), length (unique (sum.m422e$fe$year.f)))
  , c (sum.m422f$N, length (unique (sum.m422f$fe$idRegime)), length (unique (maddMain2lied[!is.na (maddMain2lied$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m422f$fe$year.f)))
  , c (sum.m412g$N, length (unique (sum.m412g$fe$idRegime)), length (unique (maddMain2lied$country)), length (unique (sum.m412g$fe$year.f)))
  , c (sum.m422g$N, length (unique (sum.m422g$fe$idRegime)), length (unique (maddMain2lied$country)), length (unique (sum.m422g$fe$year.f)))
  , c (sum.m412i$N, length (unique (sum.m412i$fe$idRegime)), length (unique (maddMain2lied$country)), length (unique (sum.m412i$fe$year.f)))
  , c (sum.m422i$N, length (unique (sum.m422i$fe$idRegime)), length (unique (maddMain2lied$country)), length (unique (sum.m422i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefRegime02tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Alternative measures of regime type (2): LIED data"
               , label="T:rRegimeLIED")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (5.2.2) Figure A23

# (5.2.2.1) Marginal effect of growth (t-1) on Pr (breakdown t):

# creating the dataset for the plots
dPlotRegime02g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotRegime02g) <- "dataset"
dPlotRegime02g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotRegime02g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotRegime02g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotRegime02g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotRegime02g$estimate <- c (coefRegime02tab[c (29, 33, 31, 35),5], coefRegime02tab[c (29, 33, 31, 35),9]
                              , coefRegime02tab[c (29, 33, 31, 35),6], coefRegime02tab[c (29, 33, 31, 35),10]
                              , coefRegime02tab[c (29, 33, 31, 35),12], coefRegime02tab[c (29, 33, 31, 35),13]
                              , coefRegime02tab[c (29, 33, 31, 35),15], coefRegime02tab[c (29, 33, 31, 35),16])
dPlotRegime02g$se <- c (coefRegime02tab[c (29, 33, 31, 35)+1,5], coefRegime02tab[c (29, 33, 31, 35)+1,9]
                        , coefRegime02tab[c (29, 33, 31, 35)+1,6], coefRegime02tab[c (29, 33, 31, 35)+1,10]
                        , coefRegime02tab[c (29, 33, 31, 35)+1,12], coefRegime02tab[c (29, 33, 31, 35)+1,13]
                        , coefRegime02tab[c (29, 33, 31, 35)+1,15], coefRegime02tab[c (29, 33, 31, 35)+1,16])
dPlotRegime02g$ciLow <- with (dPlotRegime02g, estimate + se*qt (0.025, df=n))
dPlotRegime02g$ciHigh <- with (dPlotRegime02g, estimate + se*qt (0.975, df=n))
dPlotRegime02g <- dPlotRegime02g[!is.na (dPlotRegime02g$estimate),]
dPlotRegime02g$effect <- factor (dPlotRegime02g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (5.2.2.2) Marginal effect of election (t) on Pr (breakdown t):
dPlotRegime02el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotRegime02el) <- "dataset"
dPlotRegime02el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotRegime02el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotRegime02el$growth <- rep (seq (min (maddMain2lied$madddGDPHead_lag), max (maddMain2lied$madddGDPHead_lag), length.out=m), 3)
dPlotRegime02el$estimate <- with (dPlotRegime02el, ifelse (
  elType=="actual elections\n(closed)", sum.m412e$coef[2,1]+sum.m412e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m412e$coef[2,1]+sum.m412e$coef[7,1]+(sum.m412e$coef[3,1]+sum.m412e$coef[5,1])*growth, sum.m422e$coef[2,1]+sum.m422e$coef[4,1]*growth)))
dPlotRegime02el$se <- with (dPlotRegime02el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m412e)[2,2] + (growth^2)*vcov (m412e)[3,3] + (2*growth)*vcov (m412e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m412e)[2,2] + (growth^2)*vcov (m412e)[3,3] + (1^2)*vcov (m412e)[7,7] + (growth^2)*(1^2)*vcov (m412e)[5,5] + (2*growth)*vcov (m412e)[2,3] + (2*1)*vcov (m412e)[2,7] + (2*growth*1)*vcov (m412e)[2,5] + (2*growth*1)*vcov (m412e)[3,7] + (2*1*growth^2)*vcov (m412e)[3,5] + (2*growth*1^2)*vcov (m412e)[7,5]), sqrt (vcov (m422e)[2,2] + (growth^2)*vcov (m422e)[4,4] + (2*growth)*vcov (m422e)[2,4]))))
dPlotRegime02el$ciLow <- with (dPlotRegime02el, estimate + se*qt (0.025, df=n))
dPlotRegime02el$ciHigh <- with (dPlotRegime02el, estimate + se*qt (0.975, df=n))
dPlotRegime02el <- dPlotRegime02el[abs (dPlotRegime02el$growth) <= h.lim,]

# (5.2.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectLIED01 <- ggplot (dPlotRegime02g[dPlotRegime02g$elType=="competitive\n& executive",]
                          , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectLIED02 <- ggplot (dPlotRegime02g[dPlotRegime02g$controls=="no controls",]
                          , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthLIED <- ggplot (maddMain2lied[abs (maddMain2lied$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectLIED03 <- ggplot (dPlotRegime02el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthLIED), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# (5.2.2.4) Exporting the plots
png ("Figures/fig_rRegimeLIED01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectLIED01
dev.off ()
png ("Figures/fig_rRegimeLIED02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectLIED02
dev.off ()
png ("Figures/fig_rRegimeLIED03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectLIED03
dev.off ()


## (5.3) Table A31: V-Dem coding of EARs and closed regimes
(coefRegime03a <- cbind (
  c (sum.m403a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m413a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m413c$coef[1:3,1], rep (NA, 6+5), sum.m413c$coef[1,1], sum.m413c$coef[1,1], sum.m413c$coef[1,1]+sum.m413c$coef[3,1], sum.m413c$coef[1,1]+sum.m413c$coef[3,1])
  , c (sum.m413e$coef[1:7,1], rep (NA, 2+5), sum.m413e$coef[1,1], sum.m413e$coef[1,1]+sum.m413e$coef[4,1], sum.m413e$coef[1,1]+sum.m413e$coef[3,1], sum.m413e$coef[1,1]+sum.m413e$coef[3,1]+sum.m413e$coef[4,1]+sum.m413e$coef[5,1])
  , c (sum.m413f$coef[1:7,1], rep (NA, 2+2), sum.m413f$coef[8:10,1], sum.m413f$coef[1,1], sum.m413f$coef[1,1]+sum.m413f$coef[4,1], sum.m413f$coef[1,1]+sum.m413f$coef[3,1], sum.m413f$coef[1,1]+sum.m413f$coef[3,1]+sum.m413f$coef[4,1]+sum.m413f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m423a$coef[1,1], rep (NA, 5), sum.m423a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m423e$coef[c (1:2,4),1], rep (NA, 4), sum.m423e$coef[c (3,5),1], rep (NA, 5), sum.m423e$coef[1,1], sum.m423e$coef[1,1]+sum.m423e$coef[5,1], NA, sum.m423e$coef[1,1]+sum.m423e$coef[4,1])
  , c (sum.m423f$coef[c (1:2,4),1], rep (NA, 4), sum.m423f$coef[c (3,5),1], rep (NA, 2), sum.m423f$coef[6:8,1], sum.m423f$coef[1,1], sum.m423f$coef[1,1]+sum.m423f$coef[5,1], NA, sum.m423f$coef[1,1]+sum.m423f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m413g$coef[1:7,1], rep (NA, 2+5), sum.m413g$coef[1,1], sum.m413g$coef[1,1]+sum.m413g$coef[4,1], sum.m413g$coef[1,1]+sum.m413g$coef[3,1], sum.m413g$coef[1,1]+sum.m413g$coef[3,1]+sum.m413g$coef[4,1]+sum.m413g$coef[5,1])
  , c (sum.m423g$coef[c (1:2,4),1], rep (NA, 4), sum.m423g$coef[c (3,5),1], rep (NA, 5), sum.m423g$coef[1,1], sum.m423g$coef[1,1]+sum.m423g$coef[5,1], NA, sum.m423g$coef[1,1]+sum.m423g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m413i$coef[1:7,1], rep (NA, 2+5), sum.m413i$coef[1,1], sum.m413i$coef[1,1]+sum.m413i$coef[4,1], sum.m413i$coef[1,1]+sum.m413i$coef[3,1], sum.m413i$coef[1,1]+sum.m413i$coef[3,1]+sum.m413i$coef[4,1]+sum.m413i$coef[5,1])
  , c (sum.m423i$coef[c (1:2,4),1], rep (NA, 4), sum.m423i$coef[c (3,5:7),1], rep (NA, 3), sum.m423i$coef[1,1], sum.m423i$coef[1,1]+sum.m423i$coef[5,1], NA, sum.m423i$coef[1,1]+sum.m423i$coef[4,1])))
(seRegime03a <- cbind (
  c (sum.m403a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m413a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m413c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m413c)[1,1])
       , sqrt (vcov (m413c)[1,1])
       , sqrt (vcov (m413c)[1,1]+1^2*vcov (m413c)[3,3]+2*1*vcov (m413c)[1,3])
       , sqrt (vcov (m413c)[1,1]+1^2*vcov (m413c)[3,3]+2*1*vcov (m413c)[1,3]))
  , c (sum.m413e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m413e)[1,1])
       , sqrt (vcov (m413e)[1,1]+1^2*vcov (m413e)[4,4]+2*1*vcov (m413e)[1,4])
       , sqrt (vcov (m413e)[1,1]+1^2*vcov (m413e)[3,3]+2*1*vcov (m413e)[1,3])
       , sqrt (vcov (m413e)[1,1]+1^2*vcov (m413e)[3,3]+1^2*vcov (m413e)[4,4]+1^2*1^2*vcov (m413e)[5,5]+2*1*vcov (m413e)[1,3]+2*1*vcov (m413e)[1,4]+2*1*1*vcov (m413e)[1,5]+2*1*1*vcov (m413e)[3,4]+2*1*1^2*vcov (m413e)[3,5]+2*1*1^2*vcov (m413e)[4,5]))
  , c (sum.m413f$coef[1:7,2], rep (NA, 2+2), sum.m413f$coef[8:10,2]
       , sqrt (vcov (m413f)[1,1])
       , sqrt (vcov (m413f)[1,1]+1^2*vcov (m413f)[4,4]+2*1*vcov (m413f)[1,4])
       , sqrt (vcov (m413f)[1,1]+1^2*vcov (m413f)[3,3]+2*1*vcov (m413f)[1,3])
       , sqrt (vcov (m413f)[1,1]+1^2*vcov (m413f)[3,3]+1^2*vcov (m413f)[4,4]+1^2*1^2*vcov (m413f)[5,5]+2*1*vcov (m413f)[1,3]+2*1*vcov (m413f)[1,4]+2*1*1*vcov (m413f)[1,5]+2*1*1*vcov (m413f)[3,4]+2*1*1^2*vcov (m413f)[3,5]+2*1*1^2*vcov (m413f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m423a$coef[1,2], rep (NA, 5), sum.m423a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m423e$coef[c (1:2,4),2], rep (NA, 4), sum.m423e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m423e)[1,1])
       , sqrt (vcov (m423e)[1,1]+1^2*vcov (m423e)[5,5]+2*1*vcov (m423e)[1,5])
       , NA
       , sqrt (vcov (m423e)[1,1]+1^2*vcov (m423e)[4,4]+2*1*vcov (m423e)[1,4]))
  , c (sum.m423f$coef[c (1:2,4),2], rep (NA, 4), sum.m423f$coef[c (3,5),2], rep (NA, 2), sum.m423f$coef[6:8,2]
       , sqrt (vcov (m423f)[1,1])
       , sqrt (vcov (m423f)[1,1]+1^2*vcov (m423f)[5,5]+2*1*vcov (m423f)[1,5])
       , NA
       , sqrt (vcov (m423f)[1,1]+1^2*vcov (m423f)[4,4]+2*1*vcov (m423f)[1,4]))
  , rep (NA, 18)
  , c (sum.m413g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m413g)[1,1])
       , sqrt (vcov (m413g)[1,1]+1^2*vcov (m413g)[4,4]+2*1*vcov (m413g)[1,4])
       , sqrt (vcov (m413g)[1,1]+1^2*vcov (m413g)[3,3]+2*1*vcov (m413g)[1,3])
       , sqrt (vcov (m413g)[1,1]+1^2*vcov (m413g)[3,3]+1^2*vcov (m413g)[4,4]+1^2*1^2*vcov (m413g)[5,5]+2*1*vcov (m413g)[1,3]+2*1*vcov (m413g)[1,4]+2*1*1*vcov (m413g)[1,5]+2*1*1*vcov (m413g)[3,4]+2*1*1^2*vcov (m413g)[3,5]+2*1*1^2*vcov (m413g)[4,5]))
  , c (sum.m423g$coef[c (1:2,4),2], rep (NA, 4), sum.m423g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m423g)[1,1])
       , sqrt (vcov (m423g)[1,1]+1^2*vcov (m423g)[5,5]+2*1*vcov (m423g)[1,5])
       , NA
       , sqrt (vcov (m423g)[1,1]+1^2*vcov (m423g)[4,4]+2*1*vcov (m423g)[1,4]))
  , rep (NA, 18)
  , c (sum.m413i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m413i)[1,1])
       , sqrt (vcov (m413i)[1,1]+1^2*vcov (m413i)[4,4]+2*1*vcov (m413i)[1,4])
       , sqrt (vcov (m413i)[1,1]+1^2*vcov (m413i)[3,3]+2*1*vcov (m413i)[1,3])
       , sqrt (vcov (m413i)[1,1]+1^2*vcov (m413i)[3,3]+1^2*vcov (m413i)[4,4]+1^2*1^2*vcov (m413i)[5,5]+2*1*vcov (m413i)[1,3]+2*1*vcov (m413i)[1,4]+2*1*1*vcov (m413i)[1,5]+2*1*1*vcov (m413i)[3,4]+2*1*1^2*vcov (m413i)[3,5]+2*1*1^2*vcov (m413i)[4,5]))
  , c (sum.m423i$coef[c (1:2,4),2], rep (NA, 4), sum.m423i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m423i)[1,1])
       , sqrt (vcov (m423i)[1,1]+1^2*vcov (m423i)[5,5]+2*1*vcov (m423i)[1,5])
       , NA
       , sqrt (vcov (m423i)[1,1]+1^2*vcov (m423i)[4,4]+2*1*vcov (m423i)[1,4]))))

odd <- seq (1, nrow (coefRegime03a)*2, by=2); even <- seq (2, nrow (coefRegime03a)*2, by=2)
(coefRegime03tab <- data.frame (rbind (coefRegime03a, seRegime03a))) ## warnings reported. Don't worry
rownames (coefRegime03tab) <- c (odd, even)
coefRegime03tab <- coefRegime03tab[order (as.numeric (rownames (coefRegime03tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m403a$N, length (unique (sum.m403a$fe$idRegime)), length (unique (maddMain2vdem$country)), length (unique (sum.m403a$fe$year.f)))
  , c (sum.m413a$N, length (unique (sum.m413a$fe$idRegime)), length (unique (maddMain2vdem$country)), length (unique (sum.m413a$fe$year.f)))
  , c (sum.m413c$N, length (unique (sum.m413c$fe$idRegime)), length (unique (maddMain2vdem$country)), length (unique (sum.m413c$fe$year.f)))
  , c (sum.m413e$N, length (unique (sum.m413e$fe$idRegime)), length (unique (maddMain2vdem$country)), length (unique (sum.m413e$fe$year.f)))
  , c (sum.m413f$N, length (unique (sum.m413f$fe$idRegime)), length (unique (maddMain2vdem[!is.na (maddMain2vdem$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m413f$fe$year.f)))
  , c (sum.m423a$N, length (unique (sum.m423a$fe$idRegime)), length (unique (maddMain2vdem$country)), length (unique (sum.m423a$fe$year.f)))
  , c (sum.m423e$N, length (unique (sum.m423e$fe$idRegime)), length (unique (maddMain2vdem$country)), length (unique (sum.m423e$fe$year.f)))
  , c (sum.m423f$N, length (unique (sum.m423f$fe$idRegime)), length (unique (maddMain2vdem[!is.na (maddMain2vdem$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m423f$fe$year.f)))
  , c (sum.m413g$N, length (unique (sum.m413g$fe$idRegime)), length (unique (maddMain2vdem$country)), length (unique (sum.m413g$fe$year.f)))
  , c (sum.m423g$N, length (unique (sum.m423g$fe$idRegime)), length (unique (maddMain2vdem$country)), length (unique (sum.m423g$fe$year.f)))
  , c (sum.m413i$N, length (unique (sum.m413i$fe$idRegime)), length (unique (maddMain2vdem$country)), length (unique (sum.m413i$fe$year.f)))
  , c (sum.m423i$N, length (unique (sum.m423i$fe$idRegime)), length (unique (maddMain2vdem$country)), length (unique (sum.m423i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefRegime03tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Alternative measures of regime type (3): V-Dem data"
               , label="T:rRegimeVDem")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (5.3.2) Figure A24

# (5.3.2.1) Marginal effect of growth (t-1) on Pr (breakdown t):

# creating the dataset for the plots
dPlotRegime03g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotRegime03g) <- "dataset"
dPlotRegime03g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotRegime03g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotRegime03g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotRegime03g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotRegime03g$estimate <- c (coefRegime03tab[c (29, 33, 31, 35),5], coefRegime03tab[c (29, 33, 31, 35),9]
                              , coefRegime03tab[c (29, 33, 31, 35),6], coefRegime03tab[c (29, 33, 31, 35),10]
                              , coefRegime03tab[c (29, 33, 31, 35),12], coefRegime03tab[c (29, 33, 31, 35),13]
                              , coefRegime03tab[c (29, 33, 31, 35),15], coefRegime03tab[c (29, 33, 31, 35),16])
dPlotRegime03g$se <- c (coefRegime03tab[c (29, 33, 31, 35)+1,5], coefRegime03tab[c (29, 33, 31, 35)+1,9]
                        , coefRegime03tab[c (29, 33, 31, 35)+1,6], coefRegime03tab[c (29, 33, 31, 35)+1,10]
                        , coefRegime03tab[c (29, 33, 31, 35)+1,12], coefRegime03tab[c (29, 33, 31, 35)+1,13]
                        , coefRegime03tab[c (29, 33, 31, 35)+1,15], coefRegime03tab[c (29, 33, 31, 35)+1,16])
dPlotRegime03g$ciLow <- with (dPlotRegime03g, estimate + se*qt (0.025, df=n))
dPlotRegime03g$ciHigh <- with (dPlotRegime03g, estimate + se*qt (0.975, df=n))
dPlotRegime03g <- dPlotRegime03g[!is.na (dPlotRegime03g$estimate),]
dPlotRegime03g$effect <- factor (dPlotRegime03g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (5.3.2.2) Marginal effect of election (t) on Pr (breakdown t):
dPlotRegime03el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotRegime03el) <- "dataset"
dPlotRegime03el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotRegime03el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotRegime03el$growth <- rep (seq (min (maddMain2vdem$madddGDPHead_lag), max (maddMain2vdem$madddGDPHead_lag), length.out=m), 3)
dPlotRegime03el$estimate <- with (dPlotRegime03el, ifelse (
  elType=="actual elections\n(closed)", sum.m413e$coef[2,1]+sum.m413e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m413e$coef[2,1]+sum.m413e$coef[7,1]+(sum.m413e$coef[3,1]+sum.m413e$coef[5,1])*growth, sum.m423e$coef[2,1]+sum.m423e$coef[4,1]*growth)))
dPlotRegime03el$se <- with (dPlotRegime03el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m413e)[2,2] + (growth^2)*vcov (m413e)[3,3] + (2*growth)*vcov (m413e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m413e)[2,2] + (growth^2)*vcov (m413e)[3,3] + (1^2)*vcov (m413e)[7,7] + (growth^2)*(1^2)*vcov (m413e)[5,5] + (2*growth)*vcov (m413e)[2,3] + (2*1)*vcov (m413e)[2,7] + (2*growth*1)*vcov (m413e)[2,5] + (2*growth*1)*vcov (m413e)[3,7] + (2*1*growth^2)*vcov (m413e)[3,5] + (2*growth*1^2)*vcov (m413e)[7,5]), sqrt (vcov (m423e)[2,2] + (growth^2)*vcov (m423e)[4,4] + (2*growth)*vcov (m423e)[2,4]))))
dPlotRegime03el$ciLow <- with (dPlotRegime03el, estimate + se*qt (0.025, df=n))
dPlotRegime03el$ciHigh <- with (dPlotRegime03el, estimate + se*qt (0.975, df=n))
dPlotRegime03el <- dPlotRegime03el[abs (dPlotRegime03el$growth) <= h.lim,]

# (5.3.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectVDem01 <- ggplot (dPlotRegime03g[dPlotRegime03g$elType=="competitive\n& executive",]
                          , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectVDem02 <- ggplot (dPlotRegime03g[dPlotRegime03g$controls=="no controls",]
                          , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthVDem <- ggplot (maddMain2vdem[abs (maddMain2vdem$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectVDem03 <- ggplot (dPlotRegime03el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthVDem), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# (5.3.2.4) Exporting the plots
png ("Figures/fig_rRegimeVDem01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectVDem01
dev.off ()
png ("Figures/fig_rRegimeVDem02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectVDem02
dev.off ()
png ("Figures/fig_rRegimeVDem03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectVDem03
dev.off ()





### (6) Alternative measures of economic performance: Tables A32-A34 and Figures A25-A27

## (6.1) Table A32: Recession dummy (growth rate below -5.0%)
(coefEconomic01a <- cbind (
  c (sum.m501a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m511a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m511c$coef[1:3,1], rep (NA, 6+5), sum.m511c$coef[1,1], sum.m511c$coef[1,1], sum.m511c$coef[1,1]+sum.m511c$coef[3,1], sum.m511c$coef[1,1]+sum.m511c$coef[3,1])
  , c (sum.m511e$coef[1:7,1], rep (NA, 2+5), sum.m511e$coef[1,1], sum.m511e$coef[1,1]+sum.m511e$coef[4,1], sum.m511e$coef[1,1]+sum.m511e$coef[3,1], sum.m511e$coef[1,1]+sum.m511e$coef[3,1]+sum.m511e$coef[4,1]+sum.m511e$coef[5,1])
  , c (sum.m511f$coef[1:7,1], rep (NA, 2+2), sum.m511f$coef[8:10,1], sum.m511f$coef[1,1], sum.m511f$coef[1,1]+sum.m511f$coef[4,1], sum.m511f$coef[1,1]+sum.m511f$coef[3,1], sum.m511f$coef[1,1]+sum.m511f$coef[3,1]+sum.m511f$coef[4,1]+sum.m511f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m521a$coef[1,1], rep (NA, 5), sum.m521a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m521e$coef[c (1:2,4),1], rep (NA, 4), sum.m521e$coef[c (3,5),1], rep (NA, 5), sum.m521e$coef[1,1], sum.m521e$coef[1,1]+sum.m521e$coef[5,1], NA, sum.m521e$coef[1,1]+sum.m521e$coef[4,1])
  , c (sum.m521f$coef[c (1:2,4),1], rep (NA, 4), sum.m521f$coef[c (3,5),1], rep (NA, 2), sum.m521f$coef[6:8,1], sum.m521f$coef[1,1], sum.m521f$coef[1,1]+sum.m521f$coef[5,1], NA, sum.m521f$coef[1,1]+sum.m521f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m511g$coef[1:7,1], rep (NA, 2+5), sum.m511g$coef[1,1], sum.m511g$coef[1,1]+sum.m511g$coef[4,1], sum.m511g$coef[1,1]+sum.m511g$coef[3,1], sum.m511g$coef[1,1]+sum.m511g$coef[3,1]+sum.m511g$coef[4,1]+sum.m511g$coef[5,1])
  , c (sum.m521g$coef[c (1:2,4),1], rep (NA, 4), sum.m521g$coef[c (3,5),1], rep (NA, 5), sum.m521g$coef[1,1], sum.m521g$coef[1,1]+sum.m521g$coef[5,1], NA, sum.m521g$coef[1,1]+sum.m521g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m511i$coef[1:7,1], rep (NA, 2+5), sum.m511i$coef[1,1], sum.m511i$coef[1,1]+sum.m511i$coef[4,1], sum.m511i$coef[1,1]+sum.m511i$coef[3,1], sum.m511i$coef[1,1]+sum.m511i$coef[3,1]+sum.m511i$coef[4,1]+sum.m511i$coef[5,1])
  , c (sum.m521i$coef[c (1:2,4),1], rep (NA, 4), sum.m521i$coef[c (3,5:7),1], rep (NA, 3), sum.m521i$coef[1,1], sum.m521i$coef[1,1]+sum.m521i$coef[5,1], NA, sum.m521i$coef[1,1]+sum.m521i$coef[4,1])))
(seEconomic01a <- cbind (
  c (sum.m501a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m511a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m511c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m511c)[1,1])
       , sqrt (vcov (m511c)[1,1])
       , sqrt (vcov (m511c)[1,1]+1^2*vcov (m511c)[3,3]+2*1*vcov (m511c)[1,3])
       , sqrt (vcov (m511c)[1,1]+1^2*vcov (m511c)[3,3]+2*1*vcov (m511c)[1,3]))
  , c (sum.m511e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m511e)[1,1])
       , sqrt (vcov (m511e)[1,1]+1^2*vcov (m511e)[4,4]+2*1*vcov (m511e)[1,4])
       , sqrt (vcov (m511e)[1,1]+1^2*vcov (m511e)[3,3]+2*1*vcov (m511e)[1,3])
       , sqrt (vcov (m511e)[1,1]+1^2*vcov (m511e)[3,3]+1^2*vcov (m511e)[4,4]+1^2*1^2*vcov (m511e)[5,5]+2*1*vcov (m511e)[1,3]+2*1*vcov (m511e)[1,4]+2*1*1*vcov (m511e)[1,5]+2*1*1*vcov (m511e)[3,4]+2*1*1^2*vcov (m511e)[3,5]+2*1*1^2*vcov (m511e)[4,5]))
  , c (sum.m511f$coef[1:7,2], rep (NA, 2+2), sum.m511f$coef[8:10,2]
       , sqrt (vcov (m511f)[1,1])
       , sqrt (vcov (m511f)[1,1]+1^2*vcov (m511f)[4,4]+2*1*vcov (m511f)[1,4])
       , sqrt (vcov (m511f)[1,1]+1^2*vcov (m511f)[3,3]+2*1*vcov (m511f)[1,3])
       , sqrt (vcov (m511f)[1,1]+1^2*vcov (m511f)[3,3]+1^2*vcov (m511f)[4,4]+1^2*1^2*vcov (m511f)[5,5]+2*1*vcov (m511f)[1,3]+2*1*vcov (m511f)[1,4]+2*1*1*vcov (m511f)[1,5]+2*1*1*vcov (m511f)[3,4]+2*1*1^2*vcov (m511f)[3,5]+2*1*1^2*vcov (m511f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m521a$coef[1,2], rep (NA, 5), sum.m521a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m521e$coef[c (1:2,4),2], rep (NA, 4), sum.m521e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m521e)[1,1])
       , sqrt (vcov (m521e)[1,1]+1^2*vcov (m521e)[5,5]+2*1*vcov (m521e)[1,5])
       , NA
       , sqrt (vcov (m521e)[1,1]+1^2*vcov (m521e)[4,4]+2*1*vcov (m521e)[1,4]))
  , c (sum.m521f$coef[c (1:2,4),2], rep (NA, 4), sum.m521f$coef[c (3,5),2], rep (NA, 2), sum.m521f$coef[6:8,2]
       , sqrt (vcov (m521f)[1,1])
       , sqrt (vcov (m521f)[1,1]+1^2*vcov (m521f)[5,5]+2*1*vcov (m521f)[1,5])
       , NA
       , sqrt (vcov (m521f)[1,1]+1^2*vcov (m521f)[4,4]+2*1*vcov (m521f)[1,4]))
  , rep (NA, 18)
  , c (sum.m511g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m511g)[1,1])
       , sqrt (vcov (m511g)[1,1]+1^2*vcov (m511g)[4,4]+2*1*vcov (m511g)[1,4])
       , sqrt (vcov (m511g)[1,1]+1^2*vcov (m511g)[3,3]+2*1*vcov (m511g)[1,3])
       , sqrt (vcov (m511g)[1,1]+1^2*vcov (m511g)[3,3]+1^2*vcov (m511g)[4,4]+1^2*1^2*vcov (m511g)[5,5]+2*1*vcov (m511g)[1,3]+2*1*vcov (m511g)[1,4]+2*1*1*vcov (m511g)[1,5]+2*1*1*vcov (m511g)[3,4]+2*1*1^2*vcov (m511g)[3,5]+2*1*1^2*vcov (m511g)[4,5]))
  , c (sum.m521g$coef[c (1:2,4),2], rep (NA, 4), sum.m521g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m521g)[1,1])
       , sqrt (vcov (m521g)[1,1]+1^2*vcov (m521g)[5,5]+2*1*vcov (m521g)[1,5])
       , NA
       , sqrt (vcov (m521g)[1,1]+1^2*vcov (m521g)[4,4]+2*1*vcov (m521g)[1,4]))
  , rep (NA, 18)
  , c (sum.m511i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m511i)[1,1])
       , sqrt (vcov (m511i)[1,1]+1^2*vcov (m511i)[4,4]+2*1*vcov (m511i)[1,4])
       , sqrt (vcov (m511i)[1,1]+1^2*vcov (m511i)[3,3]+2*1*vcov (m511i)[1,3])
       , sqrt (vcov (m511i)[1,1]+1^2*vcov (m511i)[3,3]+1^2*vcov (m511i)[4,4]+1^2*1^2*vcov (m511i)[5,5]+2*1*vcov (m511i)[1,3]+2*1*vcov (m511i)[1,4]+2*1*1*vcov (m511i)[1,5]+2*1*1*vcov (m511i)[3,4]+2*1*1^2*vcov (m511i)[3,5]+2*1*1^2*vcov (m511i)[4,5]))
  , c (sum.m521i$coef[c (1:2,4),2], rep (NA, 4), sum.m521i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m521i)[1,1])
       , sqrt (vcov (m521i)[1,1]+1^2*vcov (m521i)[5,5]+2*1*vcov (m521i)[1,5])
       , NA
       , sqrt (vcov (m521i)[1,1]+1^2*vcov (m521i)[4,4]+2*1*vcov (m521i)[1,4]))))

odd <- seq (1, nrow (coefEconomic01a)*2, by=2); even <- seq (2, nrow (coefEconomic01a)*2, by=2)
(coefEconomic01tab <- data.frame (rbind (coefEconomic01a, seEconomic01a))) ## warnings reported. Don't worry
rownames (coefEconomic01tab) <- c (odd, even)
coefEconomic01tab <- coefEconomic01tab[order (as.numeric (rownames (coefEconomic01tab))),]

rows <- c ("\\emph{recession}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{recession}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{recession}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{recession}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{recession}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{recession}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m501a$N, length (unique (sum.m501a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m501a$fe$year.f)))
  , c (sum.m511a$N, length (unique (sum.m511a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m511a$fe$year.f)))
  , c (sum.m511c$N, length (unique (sum.m511c$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m511c$fe$year.f)))
  , c (sum.m511e$N, length (unique (sum.m511e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m511e$fe$year.f)))
  , c (sum.m511f$N, length (unique (sum.m511f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m511f$fe$year.f)))
  , c (sum.m521a$N, length (unique (sum.m521a$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m521a$fe$year.f)))
  , c (sum.m521e$N, length (unique (sum.m521e$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m521e$fe$year.f)))
  , c (sum.m521f$N, length (unique (sum.m521f$fe$idRegime)), length (unique (maddMain[!is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m521f$fe$year.f)))
  , c (sum.m511g$N, length (unique (sum.m511g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m511g$fe$year.f)))
  , c (sum.m521g$N, length (unique (sum.m521g$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m521g$fe$year.f)))
  , c (sum.m511i$N, length (unique (sum.m511i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m511i$fe$year.f)))
  , c (sum.m521i$N, length (unique (sum.m521i$fe$idRegime)), length (unique (maddMain$country)), length (unique (sum.m521i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefEconomic01tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Alternative measures of economic performance (1): \\emph{recession}$_{t-1}$ dummy"
               , label="T:rEconomicDummy")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (6.1.2) Figure A25

# (6.1.2.1) Marginal effect of growth (t-1) on Pr (breakdown t):

# creating the dataset for the plots
dPlotEconomic01g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotEconomic01g) <- "dataset"
dPlotEconomic01g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotEconomic01g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotEconomic01g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotEconomic01g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotEconomic01g$estimate <- c (coefEconomic01tab[c (29, 33, 31, 35),5], coefEconomic01tab[c (29, 33, 31, 35),9]
                                , coefEconomic01tab[c (29, 33, 31, 35),6], coefEconomic01tab[c (29, 33, 31, 35),10]
                                , coefEconomic01tab[c (29, 33, 31, 35),12], coefEconomic01tab[c (29, 33, 31, 35),13]
                                , coefEconomic01tab[c (29, 33, 31, 35),15], coefEconomic01tab[c (29, 33, 31, 35),16])
dPlotEconomic01g$se <- c (coefEconomic01tab[c (29, 33, 31, 35)+1,5], coefEconomic01tab[c (29, 33, 31, 35)+1,9]
                          , coefEconomic01tab[c (29, 33, 31, 35)+1,6], coefEconomic01tab[c (29, 33, 31, 35)+1,10]
                          , coefEconomic01tab[c (29, 33, 31, 35)+1,12], coefEconomic01tab[c (29, 33, 31, 35)+1,13]
                          , coefEconomic01tab[c (29, 33, 31, 35)+1,15], coefEconomic01tab[c (29, 33, 31, 35)+1,16])
dPlotEconomic01g$ciLow <- with (dPlotEconomic01g, estimate + se*qt (0.025, df=n))
dPlotEconomic01g$ciHigh <- with (dPlotEconomic01g, estimate + se*qt (0.975, df=n))
dPlotEconomic01g <- dPlotEconomic01g[!is.na (dPlotEconomic01g$estimate),]
dPlotEconomic01g$effect <- factor (dPlotEconomic01g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (6.1.2.2) Marginal effect of election (t) on Pr (breakdown t):
dPlotEconomic01el <- as.data.frame (factor (c (rep ("actual elections", 2*2), rep ("scheduled elections", 2))))
colnames (dPlotEconomic01el) <- "dataset"
dPlotEconomic01el$elType <- factor (c (rep ("actual elections\n(closed)", 2), rep ("actual elections\n(EARs)", 2), rep ("scheduled elections", 2)))
dPlotEconomic01el$n <- c (rep (Ns00[1,4], 2*2), rep (Ns00[1,7], 2))
dPlotEconomic01el$recession <- factor (rep (c ("no recession", "recession"), 3))
dPlotEconomic01el$growth <- rep (c (0, 1 ), 3)
dPlotEconomic01el$estimate <- with (dPlotEconomic01el, ifelse (
  elType=="actual elections\n(closed)", sum.m511e$coef[2,1]+sum.m511e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m511e$coef[2,1]+sum.m511e$coef[7,1]+(sum.m511e$coef[3,1]+sum.m511e$coef[5,1])*growth, sum.m521e$coef[2,1]+sum.m521e$coef[4,1]*growth)))
dPlotEconomic01el$se <- with (dPlotEconomic01el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m511e)[2,2] + (growth^2)*vcov (m511e)[3,3] + (2*growth)*vcov (m511e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m511e)[2,2] + (growth^2)*vcov (m511e)[3,3] + (1^2)*vcov (m511e)[7,7] + (growth^2)*(1^2)*vcov (m511e)[5,5] + (2*growth)*vcov (m511e)[2,3] + (2*1)*vcov (m511e)[2,7] + (2*growth*1)*vcov (m511e)[2,5] + (2*growth*1)*vcov (m511e)[3,7] + (2*1*growth^2)*vcov (m511e)[3,5] + (2*growth*1^2)*vcov (m511e)[7,5]), sqrt (vcov (m521e)[2,2] + (growth^2)*vcov (m521e)[4,4] + (2*growth)*vcov (m521e)[2,4]))))
dPlotEconomic01el$ciLow <- with (dPlotEconomic01el, estimate + se*qt (0.025, df=n))
dPlotEconomic01el$ciHigh <- with (dPlotEconomic01el, estimate + se*qt (0.975, df=n))

# (6.1.2.3) Drawing the plots

# Main results for recession|elections (with and without controls)
(pEffectEconomic01 <- ggplot (dPlotEconomic01g[dPlotEconomic01g$elType=="competitive\n& executive",]
                              , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of recession (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for recession|elections
(pEffectEconomic02 <- ggplot (dPlotEconomic01g[dPlotEconomic01g$controls=="no controls",]
                              , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of recession (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main results for elections|recession
(pEffectEconomic03 <- ggplot (dPlotEconomic01el, aes (x=recession, y=estimate))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge, color=col.fill)
  + geom_point (shape=21, size=cex.text/5, position=dodge, fill=col.fill, color=col.fill)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("recession (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# (6.1.2.4) Exporting the plots
png ("Figures/fig_rEconomicDummy01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectEconomic01
dev.off ()
png ("Figures/fig_rEconomicDummy02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectEconomic02
dev.off ()
png ("Figures/fig_rEconomicDummy03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectEconomic03
dev.off ()


## (6.2) Table A33: PWT data
(coefEconomic02a <- cbind (
  c (sum.m502a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m512a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m512c$coef[1:3,1], rep (NA, 6+5), sum.m512c$coef[1,1], sum.m512c$coef[1,1], sum.m512c$coef[1,1]+sum.m512c$coef[3,1], sum.m512c$coef[1,1]+sum.m512c$coef[3,1])
  , c (sum.m512e$coef[1:7,1], rep (NA, 2+5), sum.m512e$coef[1,1], sum.m512e$coef[1,1]+sum.m512e$coef[4,1], sum.m512e$coef[1,1]+sum.m512e$coef[3,1], sum.m512e$coef[1,1]+sum.m512e$coef[3,1]+sum.m512e$coef[4,1]+sum.m512e$coef[5,1])
  , c (sum.m512f$coef[1:7,1], rep (NA, 2+2), sum.m512f$coef[8:10,1], sum.m512f$coef[1,1], sum.m512f$coef[1,1]+sum.m512f$coef[4,1], sum.m512f$coef[1,1]+sum.m512f$coef[3,1], sum.m512f$coef[1,1]+sum.m512f$coef[3,1]+sum.m512f$coef[4,1]+sum.m512f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m522a$coef[1,1], rep (NA, 5), sum.m522a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m522e$coef[c (1:2,4),1], rep (NA, 4), sum.m522e$coef[c (3,5),1], rep (NA, 5), sum.m522e$coef[1,1], sum.m522e$coef[1,1]+sum.m522e$coef[5,1], NA, sum.m522e$coef[1,1]+sum.m522e$coef[4,1])
  , c (sum.m522f$coef[c (1:2,4),1], rep (NA, 4), sum.m522f$coef[c (3,5),1], rep (NA, 2), sum.m522f$coef[6:8,1], sum.m522f$coef[1,1], sum.m522f$coef[1,1]+sum.m522f$coef[5,1], NA, sum.m522f$coef[1,1]+sum.m522f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m512g$coef[1:7,1], rep (NA, 2+5), sum.m512g$coef[1,1], sum.m512g$coef[1,1]+sum.m512g$coef[4,1], sum.m512g$coef[1,1]+sum.m512g$coef[3,1], sum.m512g$coef[1,1]+sum.m512g$coef[3,1]+sum.m512g$coef[4,1]+sum.m512g$coef[5,1])
  , c (sum.m522g$coef[c (1:2,4),1], rep (NA, 4), sum.m522g$coef[c (3,5),1], rep (NA, 5), sum.m522g$coef[1,1], sum.m522g$coef[1,1]+sum.m522g$coef[5,1], NA, sum.m522g$coef[1,1]+sum.m522g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m512i$coef[1:7,1], rep (NA, 2+5), sum.m512i$coef[1,1], sum.m512i$coef[1,1]+sum.m512i$coef[4,1], sum.m512i$coef[1,1]+sum.m512i$coef[3,1], sum.m512i$coef[1,1]+sum.m512i$coef[3,1]+sum.m512i$coef[4,1]+sum.m512i$coef[5,1])
  , c (sum.m522i$coef[c (1:2,4),1], rep (NA, 4), sum.m522i$coef[c (3,5:7),1], rep (NA, 3), sum.m522i$coef[1,1], sum.m522i$coef[1,1]+sum.m522i$coef[5,1], NA, sum.m522i$coef[1,1]+sum.m522i$coef[4,1])))
(seEconomic02a <- cbind (
  c (sum.m502a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m512a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m512c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m512c)[1,1])
       , sqrt (vcov (m512c)[1,1])
       , sqrt (vcov (m512c)[1,1]+1^2*vcov (m512c)[3,3]+2*1*vcov (m512c)[1,3])
       , sqrt (vcov (m512c)[1,1]+1^2*vcov (m512c)[3,3]+2*1*vcov (m512c)[1,3]))
  , c (sum.m512e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m512e)[1,1])
       , sqrt (vcov (m512e)[1,1]+1^2*vcov (m512e)[4,4]+2*1*vcov (m512e)[1,4])
       , sqrt (vcov (m512e)[1,1]+1^2*vcov (m512e)[3,3]+2*1*vcov (m512e)[1,3])
       , sqrt (vcov (m512e)[1,1]+1^2*vcov (m512e)[3,3]+1^2*vcov (m512e)[4,4]+1^2*1^2*vcov (m512e)[5,5]+2*1*vcov (m512e)[1,3]+2*1*vcov (m512e)[1,4]+2*1*1*vcov (m512e)[1,5]+2*1*1*vcov (m512e)[3,4]+2*1*1^2*vcov (m512e)[3,5]+2*1*1^2*vcov (m512e)[4,5]))
  , c (sum.m512f$coef[1:7,2], rep (NA, 2+2), sum.m512f$coef[8:10,2]
       , sqrt (vcov (m512f)[1,1])
       , sqrt (vcov (m512f)[1,1]+1^2*vcov (m512f)[4,4]+2*1*vcov (m512f)[1,4])
       , sqrt (vcov (m512f)[1,1]+1^2*vcov (m512f)[3,3]+2*1*vcov (m512f)[1,3])
       , sqrt (vcov (m512f)[1,1]+1^2*vcov (m512f)[3,3]+1^2*vcov (m512f)[4,4]+1^2*1^2*vcov (m512f)[5,5]+2*1*vcov (m512f)[1,3]+2*1*vcov (m512f)[1,4]+2*1*1*vcov (m512f)[1,5]+2*1*1*vcov (m512f)[3,4]+2*1*1^2*vcov (m512f)[3,5]+2*1*1^2*vcov (m512f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m522a$coef[1,2], rep (NA, 5), sum.m522a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m522e$coef[c (1:2,4),2], rep (NA, 4), sum.m522e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m522e)[1,1])
       , sqrt (vcov (m522e)[1,1]+1^2*vcov (m522e)[5,5]+2*1*vcov (m522e)[1,5])
       , NA
       , sqrt (vcov (m522e)[1,1]+1^2*vcov (m522e)[4,4]+2*1*vcov (m522e)[1,4]))
  , c (sum.m522f$coef[c (1:2,4),2], rep (NA, 4), sum.m522f$coef[c (3,5),2], rep (NA, 2), sum.m522f$coef[6:8,2]
       , sqrt (vcov (m522f)[1,1])
       , sqrt (vcov (m522f)[1,1]+1^2*vcov (m522f)[5,5]+2*1*vcov (m522f)[1,5])
       , NA
       , sqrt (vcov (m522f)[1,1]+1^2*vcov (m522f)[4,4]+2*1*vcov (m522f)[1,4]))
  , rep (NA, 18)
  , c (sum.m512g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m512g)[1,1])
       , sqrt (vcov (m512g)[1,1]+1^2*vcov (m512g)[4,4]+2*1*vcov (m512g)[1,4])
       , sqrt (vcov (m512g)[1,1]+1^2*vcov (m512g)[3,3]+2*1*vcov (m512g)[1,3])
       , sqrt (vcov (m512g)[1,1]+1^2*vcov (m512g)[3,3]+1^2*vcov (m512g)[4,4]+1^2*1^2*vcov (m512g)[5,5]+2*1*vcov (m512g)[1,3]+2*1*vcov (m512g)[1,4]+2*1*1*vcov (m512g)[1,5]+2*1*1*vcov (m512g)[3,4]+2*1*1^2*vcov (m512g)[3,5]+2*1*1^2*vcov (m512g)[4,5]))
  , c (sum.m522g$coef[c (1:2,4),2], rep (NA, 4), sum.m522g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m522g)[1,1])
       , sqrt (vcov (m522g)[1,1]+1^2*vcov (m522g)[5,5]+2*1*vcov (m522g)[1,5])
       , NA
       , sqrt (vcov (m522g)[1,1]+1^2*vcov (m522g)[4,4]+2*1*vcov (m522g)[1,4]))
  , rep (NA, 18)
  , c (sum.m512i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m512i)[1,1])
       , sqrt (vcov (m512i)[1,1]+1^2*vcov (m512i)[4,4]+2*1*vcov (m512i)[1,4])
       , sqrt (vcov (m512i)[1,1]+1^2*vcov (m512i)[3,3]+2*1*vcov (m512i)[1,3])
       , sqrt (vcov (m512i)[1,1]+1^2*vcov (m512i)[3,3]+1^2*vcov (m512i)[4,4]+1^2*1^2*vcov (m512i)[5,5]+2*1*vcov (m512i)[1,3]+2*1*vcov (m512i)[1,4]+2*1*1*vcov (m512i)[1,5]+2*1*1*vcov (m512i)[3,4]+2*1*1^2*vcov (m512i)[3,5]+2*1*1^2*vcov (m512i)[4,5]))
  , c (sum.m522i$coef[c (1:2,4),2], rep (NA, 4), sum.m522i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m522i)[1,1])
       , sqrt (vcov (m522i)[1,1]+1^2*vcov (m522i)[5,5]+2*1*vcov (m522i)[1,5])
       , NA
       , sqrt (vcov (m522i)[1,1]+1^2*vcov (m522i)[4,4]+2*1*vcov (m522i)[1,4]))))

odd <- seq (1, nrow (coefEconomic02a)*2, by=2); even <- seq (2, nrow (coefEconomic02a)*2, by=2)
(coefEconomic02tab <- data.frame (rbind (coefEconomic02a, seEconomic02a))) ## warnings reported. Don't worry
rownames (coefEconomic02tab) <- c (odd, even)
coefEconomic02tab <- coefEconomic02tab[order (as.numeric (rownames (coefEconomic02tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m502a$N, length (unique (sum.m502a$fe$idRegime)), length (unique (pwtMain$country)), length (unique (sum.m502a$fe$year.f)))
  , c (sum.m512a$N, length (unique (sum.m512a$fe$idRegime)), length (unique (pwtMain$country)), length (unique (sum.m512a$fe$year.f)))
  , c (sum.m512c$N, length (unique (sum.m512c$fe$idRegime)), length (unique (pwtMain$country)), length (unique (sum.m512c$fe$year.f)))
  , c (sum.m512e$N, length (unique (sum.m512e$fe$idRegime)), length (unique (pwtMain$country)), length (unique (sum.m512e$fe$year.f)))
  , c (sum.m512f$N, length (unique (sum.m512f$fe$idRegime)), length (unique (pwtMain[!is.na (pwtMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m512f$fe$year.f)))
  , c (sum.m522a$N, length (unique (sum.m522a$fe$idRegime)), length (unique (pwtMain$country)), length (unique (sum.m522a$fe$year.f)))
  , c (sum.m522e$N, length (unique (sum.m522e$fe$idRegime)), length (unique (pwtMain$country)), length (unique (sum.m522e$fe$year.f)))
  , c (sum.m522f$N, length (unique (sum.m522f$fe$idRegime)), length (unique (pwtMain[!is.na (pwtMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m522f$fe$year.f)))
  , c (sum.m512g$N, length (unique (sum.m512g$fe$idRegime)), length (unique (pwtMain$country)), length (unique (sum.m512g$fe$year.f)))
  , c (sum.m522g$N, length (unique (sum.m522g$fe$idRegime)), length (unique (pwtMain$country)), length (unique (sum.m522g$fe$year.f)))
  , c (sum.m512i$N, length (unique (sum.m512i$fe$idRegime)), length (unique (pwtMain$country)), length (unique (sum.m512i$fe$year.f)))
  , c (sum.m522i$N, length (unique (sum.m522i$fe$idRegime)), length (unique (pwtMain$country)), length (unique (sum.m522i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefEconomic02tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Alternative measures of economic performance (2): PWT data (1952-2015)"
               , label="T:rEconomicPWT")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (6.2.2) Figure A26

# (6.2.2.1) Marginal effect of growth (t-1) on Pr (breakdown t):

# creating the dataset for the plots
dPlotEconomic02g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotEconomic02g) <- "dataset"
dPlotEconomic02g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotEconomic02g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotEconomic02g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotEconomic02g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotEconomic02g$estimate <- c (coefEconomic02tab[c (29, 33, 31, 35),5], coefEconomic02tab[c (29, 33, 31, 35),9]
                                , coefEconomic02tab[c (29, 33, 31, 35),6], coefEconomic02tab[c (29, 33, 31, 35),10]
                                , coefEconomic02tab[c (29, 33, 31, 35),12], coefEconomic02tab[c (29, 33, 31, 35),13]
                                , coefEconomic02tab[c (29, 33, 31, 35),15], coefEconomic02tab[c (29, 33, 31, 35),16])
dPlotEconomic02g$se <- c (coefEconomic02tab[c (29, 33, 31, 35)+1,5], coefEconomic02tab[c (29, 33, 31, 35)+1,9]
                          , coefEconomic02tab[c (29, 33, 31, 35)+1,6], coefEconomic02tab[c (29, 33, 31, 35)+1,10]
                          , coefEconomic02tab[c (29, 33, 31, 35)+1,12], coefEconomic02tab[c (29, 33, 31, 35)+1,13]
                          , coefEconomic02tab[c (29, 33, 31, 35)+1,15], coefEconomic02tab[c (29, 33, 31, 35)+1,16])
dPlotEconomic02g$ciLow <- with (dPlotEconomic02g, estimate + se*qt (0.025, df=n))
dPlotEconomic02g$ciHigh <- with (dPlotEconomic02g, estimate + se*qt (0.975, df=n))
dPlotEconomic02g <- dPlotEconomic02g[!is.na (dPlotEconomic02g$estimate),]
dPlotEconomic02g$effect <- factor (dPlotEconomic02g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (6.2.2.2) Marginal effect of election (t) on Pr (breakdown t):
dPlotEconomic02el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotEconomic02el) <- "dataset"
dPlotEconomic02el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotEconomic02el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotEconomic02el$growth <- rep (seq (min (pwtMain$pwtdGDPHead_lag), max (pwtMain$pwtdGDPHead_lag), length.out=m), 3)
dPlotEconomic02el$estimate <- with (dPlotEconomic02el, ifelse (
  elType=="actual elections\n(closed)", sum.m512e$coef[2,1]+sum.m512e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m512e$coef[2,1]+sum.m512e$coef[7,1]+(sum.m512e$coef[3,1]+sum.m512e$coef[5,1])*growth, sum.m522e$coef[2,1]+sum.m522e$coef[4,1]*growth)))
dPlotEconomic02el$se <- with (dPlotEconomic02el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m512e)[2,2] + (growth^2)*vcov (m512e)[3,3] + (2*growth)*vcov (m512e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m512e)[2,2] + (growth^2)*vcov (m512e)[3,3] + (1^2)*vcov (m512e)[7,7] + (growth^2)*(1^2)*vcov (m512e)[5,5] + (2*growth)*vcov (m512e)[2,3] + (2*1)*vcov (m512e)[2,7] + (2*growth*1)*vcov (m512e)[2,5] + (2*growth*1)*vcov (m512e)[3,7] + (2*1*growth^2)*vcov (m512e)[3,5] + (2*growth*1^2)*vcov (m512e)[7,5]), sqrt (vcov (m522e)[2,2] + (growth^2)*vcov (m522e)[4,4] + (2*growth)*vcov (m522e)[2,4]))))
dPlotEconomic02el$ciLow <- with (dPlotEconomic02el, estimate + se*qt (0.025, df=n))
dPlotEconomic02el$ciHigh <- with (dPlotEconomic02el, estimate + se*qt (0.975, df=n))
dPlotEconomic02el <- dPlotEconomic02el[abs (dPlotEconomic02el$growth) <= h.lim,]

# (6.2.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectEconomic01 <- ggplot (dPlotEconomic02g[dPlotEconomic02g$elType=="competitive\n& executive",]
                              , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectEconomic02 <- ggplot (dPlotEconomic02g[dPlotEconomic02g$controls=="no controls",]
                              , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthEconomic <- ggplot (pwtMain[abs (pwtMain$pwtdGDPHead_lag) < 0.3,], aes (x=pwtdGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectEconomic03 <- ggplot (dPlotEconomic02el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthEconomic), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# (6.2.2.4) Exporting the plots
png ("Figures/fig_rEconomicPWT01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectEconomic01
dev.off ()
png ("Figures/fig_rEconomicPWT02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectEconomic02
dev.off ()
png ("Figures/fig_rEconomicPWT03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectEconomic03
dev.off ()


## (6.3) Table A34: WDI data
(coefEconomic03a <- cbind (
  c (sum.m503a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m513a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m513c$coef[1:3,1], rep (NA, 6+5), sum.m513c$coef[1,1], sum.m513c$coef[1,1], sum.m513c$coef[1,1]+sum.m513c$coef[3,1], sum.m513c$coef[1,1]+sum.m513c$coef[3,1])
  , c (sum.m513e$coef[1:7,1], rep (NA, 2+5), sum.m513e$coef[1,1], sum.m513e$coef[1,1]+sum.m513e$coef[4,1], sum.m513e$coef[1,1]+sum.m513e$coef[3,1], sum.m513e$coef[1,1]+sum.m513e$coef[3,1]+sum.m513e$coef[4,1]+sum.m513e$coef[5,1])
  , c (sum.m513f$coef[1:7,1], rep (NA, 2+2), sum.m513f$coef[8:10,1], sum.m513f$coef[1,1], sum.m513f$coef[1,1]+sum.m513f$coef[4,1], sum.m513f$coef[1,1]+sum.m513f$coef[3,1], sum.m513f$coef[1,1]+sum.m513f$coef[3,1]+sum.m513f$coef[4,1]+sum.m513f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m523a$coef[1,1], rep (NA, 5), sum.m523a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m523e$coef[c (1:2,4),1], rep (NA, 4), sum.m523e$coef[c (3,5),1], rep (NA, 5), sum.m523e$coef[1,1], sum.m523e$coef[1,1]+sum.m523e$coef[5,1], NA, sum.m523e$coef[1,1]+sum.m523e$coef[4,1])
  , c (sum.m523f$coef[c (1:2,4),1], rep (NA, 4), sum.m523f$coef[c (3,5),1], rep (NA, 2), sum.m523f$coef[6:8,1], sum.m523f$coef[1,1], sum.m523f$coef[1,1]+sum.m523f$coef[5,1], NA, sum.m523f$coef[1,1]+sum.m523f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m513g$coef[1:7,1], rep (NA, 2+5), sum.m513g$coef[1,1], sum.m513g$coef[1,1]+sum.m513g$coef[4,1], sum.m513g$coef[1,1]+sum.m513g$coef[3,1], sum.m513g$coef[1,1]+sum.m513g$coef[3,1]+sum.m513g$coef[4,1]+sum.m513g$coef[5,1])
  , c (sum.m523g$coef[c (1:2,4),1], rep (NA, 4), sum.m523g$coef[c (3,5),1], rep (NA, 5), sum.m523g$coef[1,1], sum.m523g$coef[1,1]+sum.m523g$coef[5,1], NA, sum.m523g$coef[1,1]+sum.m523g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m513i$coef[1:7,1], rep (NA, 2+5), sum.m513i$coef[1,1], sum.m513i$coef[1,1]+sum.m513i$coef[4,1], sum.m513i$coef[1,1]+sum.m513i$coef[3,1], sum.m513i$coef[1,1]+sum.m513i$coef[3,1]+sum.m513i$coef[4,1]+sum.m513i$coef[5,1])
  , c (sum.m523i$coef[c (1:2,4),1], rep (NA, 4), sum.m523i$coef[c (3,5:7),1], rep (NA, 3), sum.m523i$coef[1,1], sum.m523i$coef[1,1]+sum.m523i$coef[5,1], NA, sum.m523i$coef[1,1]+sum.m523i$coef[4,1])))
(seEconomic03a <- cbind (
  c (sum.m503a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m513a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m513c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m513c)[1,1])
       , sqrt (vcov (m513c)[1,1])
       , sqrt (vcov (m513c)[1,1]+1^2*vcov (m513c)[3,3]+2*1*vcov (m513c)[1,3])
       , sqrt (vcov (m513c)[1,1]+1^2*vcov (m513c)[3,3]+2*1*vcov (m513c)[1,3]))
  , c (sum.m513e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m513e)[1,1])
       , sqrt (vcov (m513e)[1,1]+1^2*vcov (m513e)[4,4]+2*1*vcov (m513e)[1,4])
       , sqrt (vcov (m513e)[1,1]+1^2*vcov (m513e)[3,3]+2*1*vcov (m513e)[1,3])
       , sqrt (vcov (m513e)[1,1]+1^2*vcov (m513e)[3,3]+1^2*vcov (m513e)[4,4]+1^2*1^2*vcov (m513e)[5,5]+2*1*vcov (m513e)[1,3]+2*1*vcov (m513e)[1,4]+2*1*1*vcov (m513e)[1,5]+2*1*1*vcov (m513e)[3,4]+2*1*1^2*vcov (m513e)[3,5]+2*1*1^2*vcov (m513e)[4,5]))
  , c (sum.m513f$coef[1:7,2], rep (NA, 2+2), sum.m513f$coef[8:10,2]
       , sqrt (vcov (m513f)[1,1])
       , sqrt (vcov (m513f)[1,1]+1^2*vcov (m513f)[4,4]+2*1*vcov (m513f)[1,4])
       , sqrt (vcov (m513f)[1,1]+1^2*vcov (m513f)[3,3]+2*1*vcov (m513f)[1,3])
       , sqrt (vcov (m513f)[1,1]+1^2*vcov (m513f)[3,3]+1^2*vcov (m513f)[4,4]+1^2*1^2*vcov (m513f)[5,5]+2*1*vcov (m513f)[1,3]+2*1*vcov (m513f)[1,4]+2*1*1*vcov (m513f)[1,5]+2*1*1*vcov (m513f)[3,4]+2*1*1^2*vcov (m513f)[3,5]+2*1*1^2*vcov (m513f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m523a$coef[1,2], rep (NA, 5), sum.m523a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m523e$coef[c (1:2,4),2], rep (NA, 4), sum.m523e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m523e)[1,1])
       , sqrt (vcov (m523e)[1,1]+1^2*vcov (m523e)[5,5]+2*1*vcov (m523e)[1,5])
       , NA
       , sqrt (vcov (m523e)[1,1]+1^2*vcov (m523e)[4,4]+2*1*vcov (m523e)[1,4]))
  , c (sum.m523f$coef[c (1:2,4),2], rep (NA, 4), sum.m523f$coef[c (3,5),2], rep (NA, 2), sum.m523f$coef[6:8,2]
       , sqrt (vcov (m523f)[1,1])
       , sqrt (vcov (m523f)[1,1]+1^2*vcov (m523f)[5,5]+2*1*vcov (m523f)[1,5])
       , NA
       , sqrt (vcov (m523f)[1,1]+1^2*vcov (m523f)[4,4]+2*1*vcov (m523f)[1,4]))
  , rep (NA, 18)
  , c (sum.m513g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m513g)[1,1])
       , sqrt (vcov (m513g)[1,1]+1^2*vcov (m513g)[4,4]+2*1*vcov (m513g)[1,4])
       , sqrt (vcov (m513g)[1,1]+1^2*vcov (m513g)[3,3]+2*1*vcov (m513g)[1,3])
       , sqrt (vcov (m513g)[1,1]+1^2*vcov (m513g)[3,3]+1^2*vcov (m513g)[4,4]+1^2*1^2*vcov (m513g)[5,5]+2*1*vcov (m513g)[1,3]+2*1*vcov (m513g)[1,4]+2*1*1*vcov (m513g)[1,5]+2*1*1*vcov (m513g)[3,4]+2*1*1^2*vcov (m513g)[3,5]+2*1*1^2*vcov (m513g)[4,5]))
  , c (sum.m523g$coef[c (1:2,4),2], rep (NA, 4), sum.m523g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m523g)[1,1])
       , sqrt (vcov (m523g)[1,1]+1^2*vcov (m523g)[5,5]+2*1*vcov (m523g)[1,5])
       , NA
       , sqrt (vcov (m523g)[1,1]+1^2*vcov (m523g)[4,4]+2*1*vcov (m523g)[1,4]))
  , rep (NA, 18)
  , c (sum.m513i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m513i)[1,1])
       , sqrt (vcov (m513i)[1,1]+1^2*vcov (m513i)[4,4]+2*1*vcov (m513i)[1,4])
       , sqrt (vcov (m513i)[1,1]+1^2*vcov (m513i)[3,3]+2*1*vcov (m513i)[1,3])
       , sqrt (vcov (m513i)[1,1]+1^2*vcov (m513i)[3,3]+1^2*vcov (m513i)[4,4]+1^2*1^2*vcov (m513i)[5,5]+2*1*vcov (m513i)[1,3]+2*1*vcov (m513i)[1,4]+2*1*1*vcov (m513i)[1,5]+2*1*1*vcov (m513i)[3,4]+2*1*1^2*vcov (m513i)[3,5]+2*1*1^2*vcov (m513i)[4,5]))
  , c (sum.m523i$coef[c (1:2,4),2], rep (NA, 4), sum.m523i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m523i)[1,1])
       , sqrt (vcov (m523i)[1,1]+1^2*vcov (m523i)[5,5]+2*1*vcov (m523i)[1,5])
       , NA
       , sqrt (vcov (m523i)[1,1]+1^2*vcov (m523i)[4,4]+2*1*vcov (m523i)[1,4]))))

odd <- seq (1, nrow (coefEconomic03a)*2, by=2); even <- seq (2, nrow (coefEconomic03a)*2, by=2)
(coefEconomic03tab <- data.frame (rbind (coefEconomic03a, seEconomic03a))) ## warnings reported. Don't worry
rownames (coefEconomic03tab) <- c (odd, even)
coefEconomic03tab <- coefEconomic03tab[order (as.numeric (rownames (coefEconomic03tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m503a$N, length (unique (sum.m503a$fe$idRegime)), length (unique (wdiMain$country)), length (unique (sum.m503a$fe$year.f)))
  , c (sum.m513a$N, length (unique (sum.m513a$fe$idRegime)), length (unique (wdiMain$country)), length (unique (sum.m513a$fe$year.f)))
  , c (sum.m513c$N, length (unique (sum.m513c$fe$idRegime)), length (unique (wdiMain$country)), length (unique (sum.m513c$fe$year.f)))
  , c (sum.m513e$N, length (unique (sum.m513e$fe$idRegime)), length (unique (wdiMain$country)), length (unique (sum.m513e$fe$year.f)))
  , c (sum.m513f$N, length (unique (sum.m513f$fe$idRegime)), length (unique (wdiMain[!is.na (wdiMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m513f$fe$year.f)))
  , c (sum.m523a$N, length (unique (sum.m523a$fe$idRegime)), length (unique (wdiMain$country)), length (unique (sum.m523a$fe$year.f)))
  , c (sum.m523e$N, length (unique (sum.m523e$fe$idRegime)), length (unique (wdiMain$country)), length (unique (sum.m523e$fe$year.f)))
  , c (sum.m523f$N, length (unique (sum.m523f$fe$idRegime)), length (unique (wdiMain[!is.na (wdiMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m523f$fe$year.f)))
  , c (sum.m513g$N, length (unique (sum.m513g$fe$idRegime)), length (unique (wdiMain$country)), length (unique (sum.m513g$fe$year.f)))
  , c (sum.m523g$N, length (unique (sum.m523g$fe$idRegime)), length (unique (wdiMain$country)), length (unique (sum.m523g$fe$year.f)))
  , c (sum.m513i$N, length (unique (sum.m513i$fe$idRegime)), length (unique (wdiMain$country)), length (unique (sum.m513i$fe$year.f)))
  , c (sum.m523i$N, length (unique (sum.m523i$fe$idRegime)), length (unique (wdiMain$country)), length (unique (sum.m523i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefEconomic03tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Alternative measures of economic performance (3): WDI data (1962-2015)"
               , label="T:rEconomicWDI")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (6.3.2) Figure A27

# (6.3.2.1) Marginal effect of growth (t-1) on Pr (breakdown t):

# creating the dataset for the plots
dPlotEconomic03g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotEconomic03g) <- "dataset"
dPlotEconomic03g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotEconomic03g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotEconomic03g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotEconomic03g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotEconomic03g$estimate <- c (coefEconomic03tab[c (29, 33, 31, 35),5], coefEconomic03tab[c (29, 33, 31, 35),9]
                                , coefEconomic03tab[c (29, 33, 31, 35),6], coefEconomic03tab[c (29, 33, 31, 35),10]
                                , coefEconomic03tab[c (29, 33, 31, 35),12], coefEconomic03tab[c (29, 33, 31, 35),13]
                                , coefEconomic03tab[c (29, 33, 31, 35),15], coefEconomic03tab[c (29, 33, 31, 35),16])
dPlotEconomic03g$se <- c (coefEconomic03tab[c (29, 33, 31, 35)+1,5], coefEconomic03tab[c (29, 33, 31, 35)+1,9]
                          , coefEconomic03tab[c (29, 33, 31, 35)+1,6], coefEconomic03tab[c (29, 33, 31, 35)+1,10]
                          , coefEconomic03tab[c (29, 33, 31, 35)+1,12], coefEconomic03tab[c (29, 33, 31, 35)+1,13]
                          , coefEconomic03tab[c (29, 33, 31, 35)+1,15], coefEconomic03tab[c (29, 33, 31, 35)+1,16])
dPlotEconomic03g$ciLow <- with (dPlotEconomic03g, estimate + se*qt (0.025, df=n))
dPlotEconomic03g$ciHigh <- with (dPlotEconomic03g, estimate + se*qt (0.975, df=n))
dPlotEconomic03g <- dPlotEconomic03g[!is.na (dPlotEconomic03g$estimate),]
dPlotEconomic03g$effect <- factor (dPlotEconomic03g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (6.3.2.2) Marginal effect of election (t) on Pr (breakdown t):
dPlotEconomic03el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotEconomic03el) <- "dataset"
dPlotEconomic03el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotEconomic03el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotEconomic03el$growth <- rep (seq (min (wdiMain$wdidGDPHead_lag), max (wdiMain$wdidGDPHead_lag), length.out=m), 3)
dPlotEconomic03el$estimate <- with (dPlotEconomic03el, ifelse (
  elType=="actual elections\n(closed)", sum.m513e$coef[2,1]+sum.m513e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m513e$coef[2,1]+sum.m513e$coef[7,1]+(sum.m513e$coef[3,1]+sum.m513e$coef[5,1])*growth, sum.m523e$coef[2,1]+sum.m523e$coef[4,1]*growth)))
dPlotEconomic03el$se <- with (dPlotEconomic03el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m513e)[2,2] + (growth^2)*vcov (m513e)[3,3] + (2*growth)*vcov (m513e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m513e)[2,2] + (growth^2)*vcov (m513e)[3,3] + (1^2)*vcov (m513e)[7,7] + (growth^2)*(1^2)*vcov (m513e)[5,5] + (2*growth)*vcov (m513e)[2,3] + (2*1)*vcov (m513e)[2,7] + (2*growth*1)*vcov (m513e)[2,5] + (2*growth*1)*vcov (m513e)[3,7] + (2*1*growth^2)*vcov (m513e)[3,5] + (2*growth*1^2)*vcov (m513e)[7,5]), sqrt (vcov (m523e)[2,2] + (growth^2)*vcov (m523e)[4,4] + (2*growth)*vcov (m523e)[2,4]))))
dPlotEconomic03el$ciLow <- with (dPlotEconomic03el, estimate + se*qt (0.025, df=n))
dPlotEconomic03el$ciHigh <- with (dPlotEconomic03el, estimate + se*qt (0.975, df=n))
dPlotEconomic03el <- dPlotEconomic03el[abs (dPlotEconomic03el$growth) <= h.lim,]

# (6.3.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectEconomic01 <- ggplot (dPlotEconomic03g[dPlotEconomic03g$elType=="competitive\n& executive",]
                              , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectEconomic02 <- ggplot (dPlotEconomic03g[dPlotEconomic03g$controls=="no controls",]
                              , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthEconomic <- ggplot (wdiMain[abs (wdiMain$wdidGDPHead_lag) < 0.3,], aes (x=wdidGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectEconomic03 <- ggplot (dPlotEconomic03el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthEconomic), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# (6.3.2.4) Exporting the plots
png ("Figures/fig_rEconomicWDI01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectEconomic01
dev.off ()
png ("Figures/fig_rEconomicWDI02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectEconomic02
dev.off ()
png ("Figures/fig_rEconomicWDI03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectEconomic03
dev.off ()





### (7) Split samples: Tables A32-A34 and Figures A25-A27

## (7.1) Table A35: Party-based regimes
(coefSplit01a <- cbind (
  c (sum.m601a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m611a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m611c$coef[1:3,1], rep (NA, 6+5), sum.m611c$coef[1,1], sum.m611c$coef[1,1], sum.m611c$coef[1,1]+sum.m611c$coef[3,1], sum.m611c$coef[1,1]+sum.m611c$coef[3,1])
  , c (sum.m611e$coef[1:7,1], rep (NA, 2+5), sum.m611e$coef[1,1], sum.m611e$coef[1,1]+sum.m611e$coef[4,1], sum.m611e$coef[1,1]+sum.m611e$coef[3,1], sum.m611e$coef[1,1]+sum.m611e$coef[3,1]+sum.m611e$coef[4,1]+sum.m611e$coef[5,1])
  , c (sum.m611f$coef[1:7,1], rep (NA, 2+2), sum.m611f$coef[8:10,1], sum.m611f$coef[1,1], sum.m611f$coef[1,1]+sum.m611f$coef[4,1], sum.m611f$coef[1,1]+sum.m611f$coef[3,1], sum.m611f$coef[1,1]+sum.m611f$coef[3,1]+sum.m611f$coef[4,1]+sum.m611f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m621a$coef[1,1], rep (NA, 5), sum.m621a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m621e$coef[c (1:2,4),1], rep (NA, 4), sum.m621e$coef[c (3,5),1], rep (NA, 5), sum.m621e$coef[1,1], sum.m621e$coef[1,1]+sum.m621e$coef[5,1], NA, sum.m621e$coef[1,1]+sum.m621e$coef[4,1])
  , c (sum.m621f$coef[c (1:2,4),1], rep (NA, 4), sum.m621f$coef[c (3,5),1], rep (NA, 2), sum.m621f$coef[6:8,1], sum.m621f$coef[1,1], sum.m621f$coef[1,1]+sum.m621f$coef[5,1], NA, sum.m621f$coef[1,1]+sum.m621f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m611g$coef[1:7,1], rep (NA, 2+5), sum.m611g$coef[1,1], sum.m611g$coef[1,1]+sum.m611g$coef[4,1], sum.m611g$coef[1,1]+sum.m611g$coef[3,1], sum.m611g$coef[1,1]+sum.m611g$coef[3,1]+sum.m611g$coef[4,1]+sum.m611g$coef[5,1])
  , c (sum.m621g$coef[c (1:2,4),1], rep (NA, 4), sum.m621g$coef[c (3,5),1], rep (NA, 5), sum.m621g$coef[1,1], sum.m621g$coef[1,1]+sum.m621g$coef[5,1], NA, sum.m621g$coef[1,1]+sum.m621g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m611i$coef[1:7,1], rep (NA, 2+5), sum.m611i$coef[1,1], sum.m611i$coef[1,1]+sum.m611i$coef[4,1], sum.m611i$coef[1,1]+sum.m611i$coef[3,1], sum.m611i$coef[1,1]+sum.m611i$coef[3,1]+sum.m611i$coef[4,1]+sum.m611i$coef[5,1])
  , c (sum.m621i$coef[c (1:2,4),1], rep (NA, 4), sum.m621i$coef[c (3,5:7),1], rep (NA, 3), sum.m621i$coef[1,1], sum.m621i$coef[1,1]+sum.m621i$coef[5,1], NA, sum.m621i$coef[1,1]+sum.m621i$coef[4,1])))
(seSplit01a <- cbind (
  c (sum.m601a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m611a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m611c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m611c)[1,1])
       , sqrt (vcov (m611c)[1,1])
       , sqrt (vcov (m611c)[1,1]+1^2*vcov (m611c)[3,3]+2*1*vcov (m611c)[1,3])
       , sqrt (vcov (m611c)[1,1]+1^2*vcov (m611c)[3,3]+2*1*vcov (m611c)[1,3]))
  , c (sum.m611e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m611e)[1,1])
       , sqrt (vcov (m611e)[1,1]+1^2*vcov (m611e)[4,4]+2*1*vcov (m611e)[1,4])
       , sqrt (vcov (m611e)[1,1]+1^2*vcov (m611e)[3,3]+2*1*vcov (m611e)[1,3])
       , sqrt (vcov (m611e)[1,1]+1^2*vcov (m611e)[3,3]+1^2*vcov (m611e)[4,4]+1^2*1^2*vcov (m611e)[5,5]+2*1*vcov (m611e)[1,3]+2*1*vcov (m611e)[1,4]+2*1*1*vcov (m611e)[1,5]+2*1*1*vcov (m611e)[3,4]+2*1*1^2*vcov (m611e)[3,5]+2*1*1^2*vcov (m611e)[4,5]))
  , c (sum.m611f$coef[1:7,2], rep (NA, 2+2), sum.m611f$coef[8:10,2]
       , sqrt (vcov (m611f)[1,1])
       , sqrt (vcov (m611f)[1,1]+1^2*vcov (m611f)[4,4]+2*1*vcov (m611f)[1,4])
       , sqrt (vcov (m611f)[1,1]+1^2*vcov (m611f)[3,3]+2*1*vcov (m611f)[1,3])
       , sqrt (vcov (m611f)[1,1]+1^2*vcov (m611f)[3,3]+1^2*vcov (m611f)[4,4]+1^2*1^2*vcov (m611f)[5,5]+2*1*vcov (m611f)[1,3]+2*1*vcov (m611f)[1,4]+2*1*1*vcov (m611f)[1,5]+2*1*1*vcov (m611f)[3,4]+2*1*1^2*vcov (m611f)[3,5]+2*1*1^2*vcov (m611f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m621a$coef[1,2], rep (NA, 5), sum.m621a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m621e$coef[c (1:2,4),2], rep (NA, 4), sum.m621e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m621e)[1,1])
       , sqrt (vcov (m621e)[1,1]+1^2*vcov (m621e)[5,5]+2*1*vcov (m621e)[1,5])
       , NA
       , sqrt (vcov (m621e)[1,1]+1^2*vcov (m621e)[4,4]+2*1*vcov (m621e)[1,4]))
  , c (sum.m621f$coef[c (1:2,4),2], rep (NA, 4), sum.m621f$coef[c (3,5),2], rep (NA, 2), sum.m621f$coef[6:8,2]
       , sqrt (vcov (m621f)[1,1])
       , sqrt (vcov (m621f)[1,1]+1^2*vcov (m621f)[5,5]+2*1*vcov (m621f)[1,5])
       , NA
       , sqrt (vcov (m621f)[1,1]+1^2*vcov (m621f)[4,4]+2*1*vcov (m621f)[1,4]))
  , rep (NA, 18)
  , c (sum.m611g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m611g)[1,1])
       , sqrt (vcov (m611g)[1,1]+1^2*vcov (m611g)[4,4]+2*1*vcov (m611g)[1,4])
       , sqrt (vcov (m611g)[1,1]+1^2*vcov (m611g)[3,3]+2*1*vcov (m611g)[1,3])
       , sqrt (vcov (m611g)[1,1]+1^2*vcov (m611g)[3,3]+1^2*vcov (m611g)[4,4]+1^2*1^2*vcov (m611g)[5,5]+2*1*vcov (m611g)[1,3]+2*1*vcov (m611g)[1,4]+2*1*1*vcov (m611g)[1,5]+2*1*1*vcov (m611g)[3,4]+2*1*1^2*vcov (m611g)[3,5]+2*1*1^2*vcov (m611g)[4,5]))
  , c (sum.m621g$coef[c (1:2,4),2], rep (NA, 4), sum.m621g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m621g)[1,1])
       , sqrt (vcov (m621g)[1,1]+1^2*vcov (m621g)[5,5]+2*1*vcov (m621g)[1,5])
       , NA
       , sqrt (vcov (m621g)[1,1]+1^2*vcov (m621g)[4,4]+2*1*vcov (m621g)[1,4]))
  , rep (NA, 18)
  , c (sum.m611i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m611i)[1,1])
       , sqrt (vcov (m611i)[1,1]+1^2*vcov (m611i)[4,4]+2*1*vcov (m611i)[1,4])
       , sqrt (vcov (m611i)[1,1]+1^2*vcov (m611i)[3,3]+2*1*vcov (m611i)[1,3])
       , sqrt (vcov (m611i)[1,1]+1^2*vcov (m611i)[3,3]+1^2*vcov (m611i)[4,4]+1^2*1^2*vcov (m611i)[5,5]+2*1*vcov (m611i)[1,3]+2*1*vcov (m611i)[1,4]+2*1*1*vcov (m611i)[1,5]+2*1*1*vcov (m611i)[3,4]+2*1*1^2*vcov (m611i)[3,5]+2*1*1^2*vcov (m611i)[4,5]))
  , c (sum.m621i$coef[c (1:2,4),2], rep (NA, 4), sum.m621i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m621i)[1,1])
       , sqrt (vcov (m621i)[1,1]+1^2*vcov (m621i)[5,5]+2*1*vcov (m621i)[1,5])
       , NA
       , sqrt (vcov (m621i)[1,1]+1^2*vcov (m621i)[4,4]+2*1*vcov (m621i)[1,4]))))

odd <- seq (1, nrow (coefSplit01a)*2, by=2); even <- seq (2, nrow (coefSplit01a)*2, by=2)
(coefSplit01tab <- data.frame (rbind (coefSplit01a, seSplit01a))) ## warnings reported. Don't worry
rownames (coefSplit01tab) <- c (odd, even)
coefSplit01tab <- coefSplit01tab[order (as.numeric (rownames (coefSplit01tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m601a$N, length (unique (sum.m601a$fe$idRegime)), length (unique (maddMain[maddMain$party2==1,]$country)), length (unique (sum.m601a$fe$year.f)))
  , c (sum.m611a$N, length (unique (sum.m611a$fe$idRegime)), length (unique (maddMain[maddMain$party2==1,]$country)), length (unique (sum.m611a$fe$year.f)))
  , c (sum.m611c$N, length (unique (sum.m611c$fe$idRegime)), length (unique (maddMain[maddMain$party2==1,]$country)), length (unique (sum.m611c$fe$year.f)))
  , c (sum.m611e$N, length (unique (sum.m611e$fe$idRegime)), length (unique (maddMain[maddMain$party2==1,]$country)), length (unique (sum.m611e$fe$year.f)))
  , c (sum.m611f$N, length (unique (sum.m611f$fe$idRegime)), length (unique (maddMain[maddMain$party2==1 & !is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m611f$fe$year.f)))
  , c (sum.m621a$N, length (unique (sum.m621a$fe$idRegime)), length (unique (maddMain[maddMain$party2==1,]$country)), length (unique (sum.m621a$fe$year.f)))
  , c (sum.m621e$N, length (unique (sum.m621e$fe$idRegime)), length (unique (maddMain[maddMain$party2==1,]$country)), length (unique (sum.m621e$fe$year.f)))
  , c (sum.m621f$N, length (unique (sum.m621f$fe$idRegime)), length (unique (maddMain[maddMain$party2==1 & !is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m621f$fe$year.f)))
  , c (sum.m611g$N, length (unique (sum.m611g$fe$idRegime)), length (unique (maddMain[maddMain$party2==1,]$country)), length (unique (sum.m611g$fe$year.f)))
  , c (sum.m621g$N, length (unique (sum.m621g$fe$idRegime)), length (unique (maddMain[maddMain$party2==1,]$country)), length (unique (sum.m621g$fe$year.f)))
  , c (sum.m611i$N, length (unique (sum.m611i$fe$idRegime)), length (unique (maddMain[maddMain$party2==1,]$country)), length (unique (sum.m611i$fe$year.f)))
  , c (sum.m621i$N, length (unique (sum.m621i$fe$idRegime)), length (unique (maddMain[maddMain$party2==1,]$country)), length (unique (sum.m621i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefSplit01tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Party-based regimes"
               , label="T:rSplitParty")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (7.1.2) Figure A28

# (7.1.2.1) Marginal effect of growth (t-1) on Pr (breakdown t):

# creating the dataset for the plots
dPlotSplit01g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotSplit01g) <- "dataset"
dPlotSplit01g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotSplit01g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotSplit01g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotSplit01g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotSplit01g$estimate <- c (coefSplit01tab[c (29, 33, 31, 35),5], coefSplit01tab[c (29, 33, 31, 35),9]
                             , coefSplit01tab[c (29, 33, 31, 35),6], coefSplit01tab[c (29, 33, 31, 35),10]
                             , coefSplit01tab[c (29, 33, 31, 35),12], coefSplit01tab[c (29, 33, 31, 35),13]
                             , coefSplit01tab[c (29, 33, 31, 35),15], coefSplit01tab[c (29, 33, 31, 35),16])
dPlotSplit01g$se <- c (coefSplit01tab[c (29, 33, 31, 35)+1,5], coefSplit01tab[c (29, 33, 31, 35)+1,9]
                       , coefSplit01tab[c (29, 33, 31, 35)+1,6], coefSplit01tab[c (29, 33, 31, 35)+1,10]
                       , coefSplit01tab[c (29, 33, 31, 35)+1,12], coefSplit01tab[c (29, 33, 31, 35)+1,13]
                       , coefSplit01tab[c (29, 33, 31, 35)+1,15], coefSplit01tab[c (29, 33, 31, 35)+1,16])
dPlotSplit01g$ciLow <- with (dPlotSplit01g, estimate + se*qt (0.025, df=n))
dPlotSplit01g$ciHigh <- with (dPlotSplit01g, estimate + se*qt (0.975, df=n))
dPlotSplit01g <- dPlotSplit01g[!is.na (dPlotSplit01g$estimate),]
dPlotSplit01g$effect <- factor (dPlotSplit01g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (7.1.2.2) Marginal effect of election (t) on Pr (breakdown t):
dPlotSplit01el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotSplit01el) <- "dataset"
dPlotSplit01el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotSplit01el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotSplit01el$growth <- rep (seq (min (maddMain[maddMain$party2==1,]$madddGDPHead_lag), max (maddMain[maddMain$party2==1,]$madddGDPHead_lag), length.out=m), 3)
dPlotSplit01el$estimate <- with (dPlotSplit01el, ifelse (
  elType=="actual elections\n(closed)", sum.m611e$coef[2,1]+sum.m611e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m611e$coef[2,1]+sum.m611e$coef[7,1]+(sum.m611e$coef[3,1]+sum.m611e$coef[5,1])*growth, sum.m621e$coef[2,1]+sum.m621e$coef[4,1]*growth)))
dPlotSplit01el$se <- with (dPlotSplit01el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m611e)[2,2] + (growth^2)*vcov (m611e)[3,3] + (2*growth)*vcov (m611e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m611e)[2,2] + (growth^2)*vcov (m611e)[3,3] + (1^2)*vcov (m611e)[7,7] + (growth^2)*(1^2)*vcov (m611e)[5,5] + (2*growth)*vcov (m611e)[2,3] + (2*1)*vcov (m611e)[2,7] + (2*growth*1)*vcov (m611e)[2,5] + (2*growth*1)*vcov (m611e)[3,7] + (2*1*growth^2)*vcov (m611e)[3,5] + (2*growth*1^2)*vcov (m611e)[7,5]), sqrt (vcov (m621e)[2,2] + (growth^2)*vcov (m621e)[4,4] + (2*growth)*vcov (m621e)[2,4]))))
dPlotSplit01el$ciLow <- with (dPlotSplit01el, estimate + se*qt (0.025, df=n))
dPlotSplit01el$ciHigh <- with (dPlotSplit01el, estimate + se*qt (0.975, df=n))
dPlotSplit01el <- dPlotSplit01el[abs (dPlotSplit01el$growth) <= h.lim,]

# (7.1.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectSplit01 <- ggplot (dPlotSplit01g[dPlotSplit01g$elType=="competitive\n& executive",]
                           , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectSplit02 <- ggplot (dPlotSplit01g[dPlotSplit01g$controls=="no controls",]
                           , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthSplit <- ggplot (maddMain[maddMain$party2==1 & abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectSplit03 <- ggplot (dPlotSplit01el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthSplit), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# (7.1.2.4) Exporting the plots
png ("Figures/fig_rSplitParty01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSplit01
dev.off ()
png ("Figures/fig_rSplitParty02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSplit02
dev.off ()
png ("Figures/fig_rSplitParty03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectSplit03
dev.off ()


## (7.2) Table A36: Regimes that are not party-based
(coefSplit02a <- cbind (
  c (sum.m602a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m612a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m612c$coef[1:3,1], rep (NA, 6+5), sum.m612c$coef[1,1], sum.m612c$coef[1,1], sum.m612c$coef[1,1]+sum.m612c$coef[3,1], sum.m612c$coef[1,1]+sum.m612c$coef[3,1])
  , c (sum.m612e$coef[1:7,1], rep (NA, 2+5), sum.m612e$coef[1,1], sum.m612e$coef[1,1]+sum.m612e$coef[4,1], sum.m612e$coef[1,1]+sum.m612e$coef[3,1], sum.m612e$coef[1,1]+sum.m612e$coef[3,1]+sum.m612e$coef[4,1]+sum.m612e$coef[5,1])
  , c (sum.m612f$coef[1:7,1], rep (NA, 2+2), sum.m612f$coef[8:10,1], sum.m612f$coef[1,1], sum.m612f$coef[1,1]+sum.m612f$coef[4,1], sum.m612f$coef[1,1]+sum.m612f$coef[3,1], sum.m612f$coef[1,1]+sum.m612f$coef[3,1]+sum.m612f$coef[4,1]+sum.m612f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m622a$coef[1,1], rep (NA, 5), sum.m622a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m622e$coef[c (1:2,4),1], rep (NA, 4), sum.m622e$coef[c (3,5),1], rep (NA, 5), sum.m622e$coef[1,1], sum.m622e$coef[1,1]+sum.m622e$coef[5,1], NA, sum.m622e$coef[1,1]+sum.m622e$coef[4,1])
  , c (sum.m622f$coef[c (1:2,4),1], rep (NA, 4), sum.m622f$coef[c (3,5),1], rep (NA, 2), sum.m622f$coef[6:8,1], sum.m622f$coef[1,1], sum.m622f$coef[1,1]+sum.m622f$coef[5,1], NA, sum.m622f$coef[1,1]+sum.m622f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m612g$coef[1:7,1], rep (NA, 2+5), sum.m612g$coef[1,1], sum.m612g$coef[1,1]+sum.m612g$coef[4,1], sum.m612g$coef[1,1]+sum.m612g$coef[3,1], sum.m612g$coef[1,1]+sum.m612g$coef[3,1]+sum.m612g$coef[4,1]+sum.m612g$coef[5,1])
  , c (sum.m622g$coef[c (1:2,4),1], rep (NA, 4), sum.m622g$coef[c (3,5),1], rep (NA, 5), sum.m622g$coef[1,1], sum.m622g$coef[1,1]+sum.m622g$coef[5,1], NA, sum.m622g$coef[1,1]+sum.m622g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m612i$coef[1:7,1], rep (NA, 2+5), sum.m612i$coef[1,1], sum.m612i$coef[1,1]+sum.m612i$coef[4,1], sum.m612i$coef[1,1]+sum.m612i$coef[3,1], sum.m612i$coef[1,1]+sum.m612i$coef[3,1]+sum.m612i$coef[4,1]+sum.m612i$coef[5,1])
  , c (sum.m622i$coef[c (1:2,4),1], rep (NA, 4), sum.m622i$coef[c (3,5:7),1], rep (NA, 3), sum.m622i$coef[1,1], sum.m622i$coef[1,1]+sum.m622i$coef[5,1], NA, sum.m622i$coef[1,1]+sum.m622i$coef[4,1])))
(seSplit02a <- cbind (
  c (sum.m602a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m612a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m612c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m612c)[1,1])
       , sqrt (vcov (m612c)[1,1])
       , sqrt (vcov (m612c)[1,1]+1^2*vcov (m612c)[3,3]+2*1*vcov (m612c)[1,3])
       , sqrt (vcov (m612c)[1,1]+1^2*vcov (m612c)[3,3]+2*1*vcov (m612c)[1,3]))
  , c (sum.m612e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m612e)[1,1])
       , sqrt (vcov (m612e)[1,1]+1^2*vcov (m612e)[4,4]+2*1*vcov (m612e)[1,4])
       , sqrt (vcov (m612e)[1,1]+1^2*vcov (m612e)[3,3]+2*1*vcov (m612e)[1,3])
       , sqrt (vcov (m612e)[1,1]+1^2*vcov (m612e)[3,3]+1^2*vcov (m612e)[4,4]+1^2*1^2*vcov (m612e)[5,5]+2*1*vcov (m612e)[1,3]+2*1*vcov (m612e)[1,4]+2*1*1*vcov (m612e)[1,5]+2*1*1*vcov (m612e)[3,4]+2*1*1^2*vcov (m612e)[3,5]+2*1*1^2*vcov (m612e)[4,5]))
  , c (sum.m612f$coef[1:7,2], rep (NA, 2+2), sum.m612f$coef[8:10,2]
       , sqrt (vcov (m612f)[1,1])
       , sqrt (vcov (m612f)[1,1]+1^2*vcov (m612f)[4,4]+2*1*vcov (m612f)[1,4])
       , sqrt (vcov (m612f)[1,1]+1^2*vcov (m612f)[3,3]+2*1*vcov (m612f)[1,3])
       , sqrt (vcov (m612f)[1,1]+1^2*vcov (m612f)[3,3]+1^2*vcov (m612f)[4,4]+1^2*1^2*vcov (m612f)[5,5]+2*1*vcov (m612f)[1,3]+2*1*vcov (m612f)[1,4]+2*1*1*vcov (m612f)[1,5]+2*1*1*vcov (m612f)[3,4]+2*1*1^2*vcov (m612f)[3,5]+2*1*1^2*vcov (m612f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m622a$coef[1,2], rep (NA, 5), sum.m622a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m622e$coef[c (1:2,4),2], rep (NA, 4), sum.m622e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m622e)[1,1])
       , sqrt (vcov (m622e)[1,1]+1^2*vcov (m622e)[5,5]+2*1*vcov (m622e)[1,5])
       , NA
       , sqrt (vcov (m622e)[1,1]+1^2*vcov (m622e)[4,4]+2*1*vcov (m622e)[1,4]))
  , c (sum.m622f$coef[c (1:2,4),2], rep (NA, 4), sum.m622f$coef[c (3,5),2], rep (NA, 2), sum.m622f$coef[6:8,2]
       , sqrt (vcov (m622f)[1,1])
       , sqrt (vcov (m622f)[1,1]+1^2*vcov (m622f)[5,5]+2*1*vcov (m622f)[1,5])
       , NA
       , sqrt (vcov (m622f)[1,1]+1^2*vcov (m622f)[4,4]+2*1*vcov (m622f)[1,4]))
  , rep (NA, 18)
  , c (sum.m612g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m612g)[1,1])
       , sqrt (vcov (m612g)[1,1]+1^2*vcov (m612g)[4,4]+2*1*vcov (m612g)[1,4])
       , sqrt (vcov (m612g)[1,1]+1^2*vcov (m612g)[3,3]+2*1*vcov (m612g)[1,3])
       , sqrt (vcov (m612g)[1,1]+1^2*vcov (m612g)[3,3]+1^2*vcov (m612g)[4,4]+1^2*1^2*vcov (m612g)[5,5]+2*1*vcov (m612g)[1,3]+2*1*vcov (m612g)[1,4]+2*1*1*vcov (m612g)[1,5]+2*1*1*vcov (m612g)[3,4]+2*1*1^2*vcov (m612g)[3,5]+2*1*1^2*vcov (m612g)[4,5]))
  , c (sum.m622g$coef[c (1:2,4),2], rep (NA, 4), sum.m622g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m622g)[1,1])
       , sqrt (vcov (m622g)[1,1]+1^2*vcov (m622g)[5,5]+2*1*vcov (m622g)[1,5])
       , NA
       , sqrt (vcov (m622g)[1,1]+1^2*vcov (m622g)[4,4]+2*1*vcov (m622g)[1,4]))
  , rep (NA, 18)
  , c (sum.m612i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m612i)[1,1])
       , sqrt (vcov (m612i)[1,1]+1^2*vcov (m612i)[4,4]+2*1*vcov (m612i)[1,4])
       , sqrt (vcov (m612i)[1,1]+1^2*vcov (m612i)[3,3]+2*1*vcov (m612i)[1,3])
       , sqrt (vcov (m612i)[1,1]+1^2*vcov (m612i)[3,3]+1^2*vcov (m612i)[4,4]+1^2*1^2*vcov (m612i)[5,5]+2*1*vcov (m612i)[1,3]+2*1*vcov (m612i)[1,4]+2*1*1*vcov (m612i)[1,5]+2*1*1*vcov (m612i)[3,4]+2*1*1^2*vcov (m612i)[3,5]+2*1*1^2*vcov (m612i)[4,5]))
  , c (sum.m622i$coef[c (1:2,4),2], rep (NA, 4), sum.m622i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m622i)[1,1])
       , sqrt (vcov (m622i)[1,1]+1^2*vcov (m622i)[5,5]+2*1*vcov (m622i)[1,5])
       , NA
       , sqrt (vcov (m622i)[1,1]+1^2*vcov (m622i)[4,4]+2*1*vcov (m622i)[1,4]))))

odd <- seq (1, nrow (coefSplit02a)*2, by=2); even <- seq (2, nrow (coefSplit02a)*2, by=2)
(coefSplit02tab <- data.frame (rbind (coefSplit02a, seSplit02a))) ## warnings reported. Don't worry
rownames (coefSplit02tab) <- c (odd, even)
coefSplit02tab <- coefSplit02tab[order (as.numeric (rownames (coefSplit02tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m602a$N, length (unique (sum.m602a$fe$idRegime)), length (unique (maddMain[maddMain$party2==0,]$country)), length (unique (sum.m602a$fe$year.f)))
  , c (sum.m612a$N, length (unique (sum.m612a$fe$idRegime)), length (unique (maddMain[maddMain$party2==0,]$country)), length (unique (sum.m612a$fe$year.f)))
  , c (sum.m612c$N, length (unique (sum.m612c$fe$idRegime)), length (unique (maddMain[maddMain$party2==0,]$country)), length (unique (sum.m612c$fe$year.f)))
  , c (sum.m612e$N, length (unique (sum.m612e$fe$idRegime)), length (unique (maddMain[maddMain$party2==0,]$country)), length (unique (sum.m612e$fe$year.f)))
  , c (sum.m612f$N, length (unique (sum.m612f$fe$idRegime)), length (unique (maddMain[maddMain$party2==0 & !is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m612f$fe$year.f)))
  , c (sum.m622a$N, length (unique (sum.m622a$fe$idRegime)), length (unique (maddMain[maddMain$party2==0,]$country)), length (unique (sum.m622a$fe$year.f)))
  , c (sum.m622e$N, length (unique (sum.m622e$fe$idRegime)), length (unique (maddMain[maddMain$party2==0,]$country)), length (unique (sum.m622e$fe$year.f)))
  , c (sum.m622f$N, length (unique (sum.m622f$fe$idRegime)), length (unique (maddMain[maddMain$party2==0 & !is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m622f$fe$year.f)))
  , c (sum.m612g$N, length (unique (sum.m612g$fe$idRegime)), length (unique (maddMain[maddMain$party2==0,]$country)), length (unique (sum.m612g$fe$year.f)))
  , c (sum.m622g$N, length (unique (sum.m622g$fe$idRegime)), length (unique (maddMain[maddMain$party2==0,]$country)), length (unique (sum.m622g$fe$year.f)))
  , c (sum.m612i$N, length (unique (sum.m612i$fe$idRegime)), length (unique (maddMain[maddMain$party2==0,]$country)), length (unique (sum.m612i$fe$year.f)))
  , c (sum.m622i$N, length (unique (sum.m622i$fe$idRegime)), length (unique (maddMain[maddMain$party2==0,]$country)), length (unique (sum.m622i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefSplit02tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Regimes that are not party-based"
               , label="T:rSplitNoParty")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (7.2.2) Figure A29

# (7.2.2.1) Marginal effect of growth (t-1) on Pr (breakdown t):

# creating the dataset for the plots
dPlotSplit02g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotSplit02g) <- "dataset"
dPlotSplit02g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotSplit02g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotSplit02g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotSplit02g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotSplit02g$estimate <- c (coefSplit02tab[c (29, 33, 31, 35),5], coefSplit02tab[c (29, 33, 31, 35),9]
                             , coefSplit02tab[c (29, 33, 31, 35),6], coefSplit02tab[c (29, 33, 31, 35),10]
                             , coefSplit02tab[c (29, 33, 31, 35),12], coefSplit02tab[c (29, 33, 31, 35),13]
                             , coefSplit02tab[c (29, 33, 31, 35),15], coefSplit02tab[c (29, 33, 31, 35),16])
dPlotSplit02g$se <- c (coefSplit02tab[c (29, 33, 31, 35)+1,5], coefSplit02tab[c (29, 33, 31, 35)+1,9]
                       , coefSplit02tab[c (29, 33, 31, 35)+1,6], coefSplit02tab[c (29, 33, 31, 35)+1,10]
                       , coefSplit02tab[c (29, 33, 31, 35)+1,12], coefSplit02tab[c (29, 33, 31, 35)+1,13]
                       , coefSplit02tab[c (29, 33, 31, 35)+1,15], coefSplit02tab[c (29, 33, 31, 35)+1,16])
dPlotSplit02g$ciLow <- with (dPlotSplit02g, estimate + se*qt (0.025, df=n))
dPlotSplit02g$ciHigh <- with (dPlotSplit02g, estimate + se*qt (0.975, df=n))
dPlotSplit02g <- dPlotSplit02g[!is.na (dPlotSplit02g$estimate),]
dPlotSplit02g$effect <- factor (dPlotSplit02g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (7.2.2.2) Marginal effect of election (t) on Pr (breakdown t):
dPlotSplit02el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotSplit02el) <- "dataset"
dPlotSplit02el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotSplit02el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotSplit02el$growth <- rep (seq (min (maddMain[maddMain$party2==0,]$madddGDPHead_lag), max (maddMain[maddMain$party2==0,]$madddGDPHead_lag), length.out=m), 3)
dPlotSplit02el$estimate <- with (dPlotSplit02el, ifelse (
  elType=="actual elections\n(closed)", sum.m612e$coef[2,1]+sum.m612e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m612e$coef[2,1]+sum.m612e$coef[7,1]+(sum.m612e$coef[3,1]+sum.m612e$coef[5,1])*growth, sum.m622e$coef[2,1]+sum.m622e$coef[4,1]*growth)))
dPlotSplit02el$se <- with (dPlotSplit02el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m612e)[2,2] + (growth^2)*vcov (m612e)[3,3] + (2*growth)*vcov (m612e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m612e)[2,2] + (growth^2)*vcov (m612e)[3,3] + (1^2)*vcov (m612e)[7,7] + (growth^2)*(1^2)*vcov (m612e)[5,5] + (2*growth)*vcov (m612e)[2,3] + (2*1)*vcov (m612e)[2,7] + (2*growth*1)*vcov (m612e)[2,5] + (2*growth*1)*vcov (m612e)[3,7] + (2*1*growth^2)*vcov (m612e)[3,5] + (2*growth*1^2)*vcov (m612e)[7,5]), sqrt (vcov (m622e)[2,2] + (growth^2)*vcov (m622e)[4,4] + (2*growth)*vcov (m622e)[2,4]))))
dPlotSplit02el$ciLow <- with (dPlotSplit02el, estimate + se*qt (0.025, df=n))
dPlotSplit02el$ciHigh <- with (dPlotSplit02el, estimate + se*qt (0.975, df=n))
dPlotSplit02el <- dPlotSplit02el[abs (dPlotSplit02el$growth) <= h.lim,]

# (7.2.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectSplit01 <- ggplot (dPlotSplit02g[dPlotSplit02g$elType=="competitive\n& executive",]
                           , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectSplit02 <- ggplot (dPlotSplit02g[dPlotSplit02g$controls=="no controls",]
                           , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthSplit <- ggplot (maddMain[maddMain$party2==0 & abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectSplit03 <- ggplot (dPlotSplit02el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthSplit), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# (7.2.2.4) Exporting the plots
png ("Figures/fig_rSplitNoParty01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSplit01
dev.off ()
png ("Figures/fig_rSplitNoParty02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSplit02
dev.off ()
png ("Figures/fig_rSplitNoParty03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectSplit03
dev.off ()


## (7.3) Table A37: Poor countries
(coefSplit03a <- cbind (
  c (sum.m603a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m613a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m613c$coef[1:3,1], rep (NA, 6+5), sum.m613c$coef[1,1], sum.m613c$coef[1,1], sum.m613c$coef[1,1]+sum.m613c$coef[3,1], sum.m613c$coef[1,1]+sum.m613c$coef[3,1])
  , c (sum.m613e$coef[1:7,1], rep (NA, 2+5), sum.m613e$coef[1,1], sum.m613e$coef[1,1]+sum.m613e$coef[4,1], sum.m613e$coef[1,1]+sum.m613e$coef[3,1], sum.m613e$coef[1,1]+sum.m613e$coef[3,1]+sum.m613e$coef[4,1]+sum.m613e$coef[5,1])
  , c (sum.m613f$coef[1:7,1], rep (NA, 2+2), sum.m613f$coef[8:10,1], sum.m613f$coef[1,1], sum.m613f$coef[1,1]+sum.m613f$coef[4,1], sum.m613f$coef[1,1]+sum.m613f$coef[3,1], sum.m613f$coef[1,1]+sum.m613f$coef[3,1]+sum.m613f$coef[4,1]+sum.m613f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m623a$coef[1,1], rep (NA, 5), sum.m623a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m623e$coef[c (1:2,4),1], rep (NA, 4), sum.m623e$coef[c (3,5),1], rep (NA, 5), sum.m623e$coef[1,1], sum.m623e$coef[1,1]+sum.m623e$coef[5,1], NA, sum.m623e$coef[1,1]+sum.m623e$coef[4,1])
  , c (sum.m623f$coef[c (1:2,4),1], rep (NA, 4), sum.m623f$coef[c (3,5),1], rep (NA, 2), sum.m623f$coef[6:8,1], sum.m623f$coef[1,1], sum.m623f$coef[1,1]+sum.m623f$coef[5,1], NA, sum.m623f$coef[1,1]+sum.m623f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m613g$coef[1:7,1], rep (NA, 2+5), sum.m613g$coef[1,1], sum.m613g$coef[1,1]+sum.m613g$coef[4,1], sum.m613g$coef[1,1]+sum.m613g$coef[3,1], sum.m613g$coef[1,1]+sum.m613g$coef[3,1]+sum.m613g$coef[4,1]+sum.m613g$coef[5,1])
  , c (sum.m623g$coef[c (1:2,4),1], rep (NA, 4), sum.m623g$coef[c (3,5),1], rep (NA, 5), sum.m623g$coef[1,1], sum.m623g$coef[1,1]+sum.m623g$coef[5,1], NA, sum.m623g$coef[1,1]+sum.m623g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m613i$coef[1:7,1], rep (NA, 2+5), sum.m613i$coef[1,1], sum.m613i$coef[1,1]+sum.m613i$coef[4,1], sum.m613i$coef[1,1]+sum.m613i$coef[3,1], sum.m613i$coef[1,1]+sum.m613i$coef[3,1]+sum.m613i$coef[4,1]+sum.m613i$coef[5,1])
  , c (sum.m623i$coef[c (1:2,4),1], rep (NA, 4), sum.m623i$coef[c (3,5:7),1], rep (NA, 3), sum.m623i$coef[1,1], sum.m623i$coef[1,1]+sum.m623i$coef[5,1], NA, sum.m623i$coef[1,1]+sum.m623i$coef[4,1])))
(seSplit03a <- cbind (
  c (sum.m603a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m613a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m613c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m613c)[1,1])
       , sqrt (vcov (m613c)[1,1])
       , sqrt (vcov (m613c)[1,1]+1^2*vcov (m613c)[3,3]+2*1*vcov (m613c)[1,3])
       , sqrt (vcov (m613c)[1,1]+1^2*vcov (m613c)[3,3]+2*1*vcov (m613c)[1,3]))
  , c (sum.m613e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m613e)[1,1])
       , sqrt (vcov (m613e)[1,1]+1^2*vcov (m613e)[4,4]+2*1*vcov (m613e)[1,4])
       , sqrt (vcov (m613e)[1,1]+1^2*vcov (m613e)[3,3]+2*1*vcov (m613e)[1,3])
       , sqrt (vcov (m613e)[1,1]+1^2*vcov (m613e)[3,3]+1^2*vcov (m613e)[4,4]+1^2*1^2*vcov (m613e)[5,5]+2*1*vcov (m613e)[1,3]+2*1*vcov (m613e)[1,4]+2*1*1*vcov (m613e)[1,5]+2*1*1*vcov (m613e)[3,4]+2*1*1^2*vcov (m613e)[3,5]+2*1*1^2*vcov (m613e)[4,5]))
  , c (sum.m613f$coef[1:7,2], rep (NA, 2+2), sum.m613f$coef[8:10,2]
       , sqrt (vcov (m613f)[1,1])
       , sqrt (vcov (m613f)[1,1]+1^2*vcov (m613f)[4,4]+2*1*vcov (m613f)[1,4])
       , sqrt (vcov (m613f)[1,1]+1^2*vcov (m613f)[3,3]+2*1*vcov (m613f)[1,3])
       , sqrt (vcov (m613f)[1,1]+1^2*vcov (m613f)[3,3]+1^2*vcov (m613f)[4,4]+1^2*1^2*vcov (m613f)[5,5]+2*1*vcov (m613f)[1,3]+2*1*vcov (m613f)[1,4]+2*1*1*vcov (m613f)[1,5]+2*1*1*vcov (m613f)[3,4]+2*1*1^2*vcov (m613f)[3,5]+2*1*1^2*vcov (m613f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m623a$coef[1,2], rep (NA, 5), sum.m623a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m623e$coef[c (1:2,4),2], rep (NA, 4), sum.m623e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m623e)[1,1])
       , sqrt (vcov (m623e)[1,1]+1^2*vcov (m623e)[5,5]+2*1*vcov (m623e)[1,5])
       , NA
       , sqrt (vcov (m623e)[1,1]+1^2*vcov (m623e)[4,4]+2*1*vcov (m623e)[1,4]))
  , c (sum.m623f$coef[c (1:2,4),2], rep (NA, 4), sum.m623f$coef[c (3,5),2], rep (NA, 2), sum.m623f$coef[6:8,2]
       , sqrt (vcov (m623f)[1,1])
       , sqrt (vcov (m623f)[1,1]+1^2*vcov (m623f)[5,5]+2*1*vcov (m623f)[1,5])
       , NA
       , sqrt (vcov (m623f)[1,1]+1^2*vcov (m623f)[4,4]+2*1*vcov (m623f)[1,4]))
  , rep (NA, 18)
  , c (sum.m613g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m613g)[1,1])
       , sqrt (vcov (m613g)[1,1]+1^2*vcov (m613g)[4,4]+2*1*vcov (m613g)[1,4])
       , sqrt (vcov (m613g)[1,1]+1^2*vcov (m613g)[3,3]+2*1*vcov (m613g)[1,3])
       , sqrt (vcov (m613g)[1,1]+1^2*vcov (m613g)[3,3]+1^2*vcov (m613g)[4,4]+1^2*1^2*vcov (m613g)[5,5]+2*1*vcov (m613g)[1,3]+2*1*vcov (m613g)[1,4]+2*1*1*vcov (m613g)[1,5]+2*1*1*vcov (m613g)[3,4]+2*1*1^2*vcov (m613g)[3,5]+2*1*1^2*vcov (m613g)[4,5]))
  , c (sum.m623g$coef[c (1:2,4),2], rep (NA, 4), sum.m623g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m623g)[1,1])
       , sqrt (vcov (m623g)[1,1]+1^2*vcov (m623g)[5,5]+2*1*vcov (m623g)[1,5])
       , NA
       , sqrt (vcov (m623g)[1,1]+1^2*vcov (m623g)[4,4]+2*1*vcov (m623g)[1,4]))
  , rep (NA, 18)
  , c (sum.m613i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m613i)[1,1])
       , sqrt (vcov (m613i)[1,1]+1^2*vcov (m613i)[4,4]+2*1*vcov (m613i)[1,4])
       , sqrt (vcov (m613i)[1,1]+1^2*vcov (m613i)[3,3]+2*1*vcov (m613i)[1,3])
       , sqrt (vcov (m613i)[1,1]+1^2*vcov (m613i)[3,3]+1^2*vcov (m613i)[4,4]+1^2*1^2*vcov (m613i)[5,5]+2*1*vcov (m613i)[1,3]+2*1*vcov (m613i)[1,4]+2*1*1*vcov (m613i)[1,5]+2*1*1*vcov (m613i)[3,4]+2*1*1^2*vcov (m613i)[3,5]+2*1*1^2*vcov (m613i)[4,5]))
  , c (sum.m623i$coef[c (1:2,4),2], rep (NA, 4), sum.m623i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m623i)[1,1])
       , sqrt (vcov (m623i)[1,1]+1^2*vcov (m623i)[5,5]+2*1*vcov (m623i)[1,5])
       , NA
       , sqrt (vcov (m623i)[1,1]+1^2*vcov (m623i)[4,4]+2*1*vcov (m623i)[1,4]))))

odd <- seq (1, nrow (coefSplit03a)*2, by=2); even <- seq (2, nrow (coefSplit03a)*2, by=2)
(coefSplit03tab <- data.frame (rbind (coefSplit03a, seSplit03a))) ## warnings reported. Don't worry
rownames (coefSplit03tab) <- c (odd, even)
coefSplit03tab <- coefSplit03tab[order (as.numeric (rownames (coefSplit03tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m603a$N, length (unique (sum.m603a$fe$idRegime)), length (unique (maddMain[maddMain$poor50==1,]$country)), length (unique (sum.m603a$fe$year.f)))
  , c (sum.m613a$N, length (unique (sum.m613a$fe$idRegime)), length (unique (maddMain[maddMain$poor50==1,]$country)), length (unique (sum.m613a$fe$year.f)))
  , c (sum.m613c$N, length (unique (sum.m613c$fe$idRegime)), length (unique (maddMain[maddMain$poor50==1,]$country)), length (unique (sum.m613c$fe$year.f)))
  , c (sum.m613e$N, length (unique (sum.m613e$fe$idRegime)), length (unique (maddMain[maddMain$poor50==1,]$country)), length (unique (sum.m613e$fe$year.f)))
  , c (sum.m613f$N, length (unique (sum.m613f$fe$idRegime)), length (unique (maddMain[maddMain$poor50==1 & !is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m613f$fe$year.f)))
  , c (sum.m623a$N, length (unique (sum.m623a$fe$idRegime)), length (unique (maddMain[maddMain$poor50==1,]$country)), length (unique (sum.m623a$fe$year.f)))
  , c (sum.m623e$N, length (unique (sum.m623e$fe$idRegime)), length (unique (maddMain[maddMain$poor50==1,]$country)), length (unique (sum.m623e$fe$year.f)))
  , c (sum.m623f$N, length (unique (sum.m623f$fe$idRegime)), length (unique (maddMain[maddMain$poor50==1 & !is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m623f$fe$year.f)))
  , c (sum.m613g$N, length (unique (sum.m613g$fe$idRegime)), length (unique (maddMain[maddMain$poor50==1,]$country)), length (unique (sum.m613g$fe$year.f)))
  , c (sum.m623g$N, length (unique (sum.m623g$fe$idRegime)), length (unique (maddMain[maddMain$poor50==1,]$country)), length (unique (sum.m623g$fe$year.f)))
  , c (sum.m613i$N, length (unique (sum.m613i$fe$idRegime)), length (unique (maddMain[maddMain$poor50==1,]$country)), length (unique (sum.m613i$fe$year.f)))
  , c (sum.m623i$N, length (unique (sum.m623i$fe$idRegime)), length (unique (maddMain[maddMain$poor50==1,]$country)), length (unique (sum.m623i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefSplit03tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Poor countries"
               , label="T:rSplitPoor")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (7.3.2) Figure A30

# (7.3.2.1) Marginal effect of growth (t-1) on Pr (breakdown t):

# creating the dataset for the plots
dPlotSplit03g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotSplit03g) <- "dataset"
dPlotSplit03g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotSplit03g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotSplit03g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotSplit03g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotSplit03g$estimate <- c (coefSplit03tab[c (29, 33, 31, 35),5], coefSplit03tab[c (29, 33, 31, 35),9]
                             , coefSplit03tab[c (29, 33, 31, 35),6], coefSplit03tab[c (29, 33, 31, 35),10]
                             , coefSplit03tab[c (29, 33, 31, 35),12], coefSplit03tab[c (29, 33, 31, 35),13]
                             , coefSplit03tab[c (29, 33, 31, 35),15], coefSplit03tab[c (29, 33, 31, 35),16])
dPlotSplit03g$se <- c (coefSplit03tab[c (29, 33, 31, 35)+1,5], coefSplit03tab[c (29, 33, 31, 35)+1,9]
                       , coefSplit03tab[c (29, 33, 31, 35)+1,6], coefSplit03tab[c (29, 33, 31, 35)+1,10]
                       , coefSplit03tab[c (29, 33, 31, 35)+1,12], coefSplit03tab[c (29, 33, 31, 35)+1,13]
                       , coefSplit03tab[c (29, 33, 31, 35)+1,15], coefSplit03tab[c (29, 33, 31, 35)+1,16])
dPlotSplit03g$ciLow <- with (dPlotSplit03g, estimate + se*qt (0.025, df=n))
dPlotSplit03g$ciHigh <- with (dPlotSplit03g, estimate + se*qt (0.975, df=n))
dPlotSplit03g <- dPlotSplit03g[!is.na (dPlotSplit03g$estimate),]
dPlotSplit03g$effect <- factor (dPlotSplit03g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (7.3.2.2) Marginal effect of election (t) on Pr (breakdown t):
dPlotSplit03el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotSplit03el) <- "dataset"
dPlotSplit03el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotSplit03el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotSplit03el$growth <- rep (seq (min (maddMain[maddMain$poor50==1,]$madddGDPHead_lag), max (maddMain[maddMain$poor50==1,]$madddGDPHead_lag), length.out=m), 3)
dPlotSplit03el$estimate <- with (dPlotSplit03el, ifelse (
  elType=="actual elections\n(closed)", sum.m613e$coef[2,1]+sum.m613e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m613e$coef[2,1]+sum.m613e$coef[7,1]+(sum.m613e$coef[3,1]+sum.m613e$coef[5,1])*growth, sum.m623e$coef[2,1]+sum.m623e$coef[4,1]*growth)))
dPlotSplit03el$se <- with (dPlotSplit03el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m613e)[2,2] + (growth^2)*vcov (m613e)[3,3] + (2*growth)*vcov (m613e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m613e)[2,2] + (growth^2)*vcov (m613e)[3,3] + (1^2)*vcov (m613e)[7,7] + (growth^2)*(1^2)*vcov (m613e)[5,5] + (2*growth)*vcov (m613e)[2,3] + (2*1)*vcov (m613e)[2,7] + (2*growth*1)*vcov (m613e)[2,5] + (2*growth*1)*vcov (m613e)[3,7] + (2*1*growth^2)*vcov (m613e)[3,5] + (2*growth*1^2)*vcov (m613e)[7,5]), sqrt (vcov (m623e)[2,2] + (growth^2)*vcov (m623e)[4,4] + (2*growth)*vcov (m623e)[2,4]))))
dPlotSplit03el$ciLow <- with (dPlotSplit03el, estimate + se*qt (0.025, df=n))
dPlotSplit03el$ciHigh <- with (dPlotSplit03el, estimate + se*qt (0.975, df=n))
dPlotSplit03el <- dPlotSplit03el[abs (dPlotSplit03el$growth) <= h.lim,]

# (7.3.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectSplit01 <- ggplot (dPlotSplit03g[dPlotSplit03g$elType=="competitive\n& executive",]
                           , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectSplit02 <- ggplot (dPlotSplit03g[dPlotSplit03g$controls=="no controls",]
                           , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthSplit <- ggplot (maddMain[maddMain$poor50==1 & abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectSplit03 <- ggplot (dPlotSplit03el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthSplit), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# (7.3.2.4) Exporting the plots
png ("Figures/fig_rSplitPoor01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSplit01
dev.off ()
png ("Figures/fig_rSplitPoor02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSplit02
dev.off ()
png ("Figures/fig_rSplitPoor03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectSplit03
dev.off ()


## (7.4) Table A38: Poor countries
(coefSplit04a <- cbind (
  c (sum.m604a$coef[1,1], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m614a$coef[1,1], rep (NA, 7+5+4))
  , c (sum.m614c$coef[1:3,1], rep (NA, 6+5), sum.m614c$coef[1,1], sum.m614c$coef[1,1], sum.m614c$coef[1,1]+sum.m614c$coef[3,1], sum.m614c$coef[1,1]+sum.m614c$coef[3,1])
  , c (sum.m614e$coef[1:7,1], rep (NA, 2+5), sum.m614e$coef[1,1], sum.m614e$coef[1,1]+sum.m614e$coef[4,1], sum.m614e$coef[1,1]+sum.m614e$coef[3,1], sum.m614e$coef[1,1]+sum.m614e$coef[3,1]+sum.m614e$coef[4,1]+sum.m614e$coef[5,1])
  , c (sum.m614f$coef[1:7,1], rep (NA, 2+2), sum.m614f$coef[8:10,1], sum.m614f$coef[1,1], sum.m614f$coef[1,1]+sum.m614f$coef[4,1], sum.m614f$coef[1,1]+sum.m614f$coef[3,1], sum.m614f$coef[1,1]+sum.m614f$coef[3,1]+sum.m614f$coef[4,1]+sum.m614f$coef[5,1])
  , rep (NA, 18)
  , c (NA, sum.m624a$coef[1,1], rep (NA, 5), sum.m624a$coef[2,1], rep (NA, 1+5+4))
  , c (sum.m624e$coef[c (1:2,4),1], rep (NA, 4), sum.m624e$coef[c (3,5),1], rep (NA, 5), sum.m624e$coef[1,1], sum.m624e$coef[1,1]+sum.m624e$coef[5,1], NA, sum.m624e$coef[1,1]+sum.m624e$coef[4,1])
  , c (sum.m624f$coef[c (1:2,4),1], rep (NA, 4), sum.m624f$coef[c (3,5),1], rep (NA, 2), sum.m624f$coef[6:8,1], sum.m624f$coef[1,1], sum.m624f$coef[1,1]+sum.m624f$coef[5,1], NA, sum.m624f$coef[1,1]+sum.m624f$coef[4,1])
  , rep (NA, 18)
  , c (sum.m614g$coef[1:7,1], rep (NA, 2+5), sum.m614g$coef[1,1], sum.m614g$coef[1,1]+sum.m614g$coef[4,1], sum.m614g$coef[1,1]+sum.m614g$coef[3,1], sum.m614g$coef[1,1]+sum.m614g$coef[3,1]+sum.m614g$coef[4,1]+sum.m614g$coef[5,1])
  , c (sum.m624g$coef[c (1:2,4),1], rep (NA, 4), sum.m624g$coef[c (3,5),1], rep (NA, 5), sum.m624g$coef[1,1], sum.m624g$coef[1,1]+sum.m624g$coef[5,1], NA, sum.m624g$coef[1,1]+sum.m624g$coef[4,1])
  , rep (NA, 18)
  , c (sum.m614i$coef[1:7,1], rep (NA, 2+5), sum.m614i$coef[1,1], sum.m614i$coef[1,1]+sum.m614i$coef[4,1], sum.m614i$coef[1,1]+sum.m614i$coef[3,1], sum.m614i$coef[1,1]+sum.m614i$coef[3,1]+sum.m614i$coef[4,1]+sum.m614i$coef[5,1])
  , c (sum.m624i$coef[c (1:2,4),1], rep (NA, 4), sum.m624i$coef[c (3,5:7),1], rep (NA, 3), sum.m624i$coef[1,1], sum.m624i$coef[1,1]+sum.m624i$coef[5,1], NA, sum.m624i$coef[1,1]+sum.m624i$coef[4,1])))
(seSplit04a <- cbind (
  c (sum.m604a$coef[1,2], rep (NA, 8+5+4))
  , rep (NA, 18)
  , c (NA, sum.m614a$coef[1,2], rep (NA, 7+5+4))
  , c (sum.m614c$coef[1:3,2], rep (NA, 6+5)
       , sqrt (vcov (m614c)[1,1])
       , sqrt (vcov (m614c)[1,1])
       , sqrt (vcov (m614c)[1,1]+1^2*vcov (m614c)[3,3]+2*1*vcov (m614c)[1,3])
       , sqrt (vcov (m614c)[1,1]+1^2*vcov (m614c)[3,3]+2*1*vcov (m614c)[1,3]))
  , c (sum.m614e$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m614e)[1,1])
       , sqrt (vcov (m614e)[1,1]+1^2*vcov (m614e)[4,4]+2*1*vcov (m614e)[1,4])
       , sqrt (vcov (m614e)[1,1]+1^2*vcov (m614e)[3,3]+2*1*vcov (m614e)[1,3])
       , sqrt (vcov (m614e)[1,1]+1^2*vcov (m614e)[3,3]+1^2*vcov (m614e)[4,4]+1^2*1^2*vcov (m614e)[5,5]+2*1*vcov (m614e)[1,3]+2*1*vcov (m614e)[1,4]+2*1*1*vcov (m614e)[1,5]+2*1*1*vcov (m614e)[3,4]+2*1*1^2*vcov (m614e)[3,5]+2*1*1^2*vcov (m614e)[4,5]))
  , c (sum.m614f$coef[1:7,2], rep (NA, 2+2), sum.m614f$coef[8:10,2]
       , sqrt (vcov (m614f)[1,1])
       , sqrt (vcov (m614f)[1,1]+1^2*vcov (m614f)[4,4]+2*1*vcov (m614f)[1,4])
       , sqrt (vcov (m614f)[1,1]+1^2*vcov (m614f)[3,3]+2*1*vcov (m614f)[1,3])
       , sqrt (vcov (m614f)[1,1]+1^2*vcov (m614f)[3,3]+1^2*vcov (m614f)[4,4]+1^2*1^2*vcov (m614f)[5,5]+2*1*vcov (m614f)[1,3]+2*1*vcov (m614f)[1,4]+2*1*1*vcov (m614f)[1,5]+2*1*1*vcov (m614f)[3,4]+2*1*1^2*vcov (m614f)[3,5]+2*1*1^2*vcov (m614f)[4,5]))
  , rep (NA, 18)
  , c (NA, sum.m624a$coef[1,2], rep (NA, 5), sum.m624a$coef[2,2], rep (NA, 1+5+4))
  , c (sum.m624e$coef[c (1:2,4),2], rep (NA, 4), sum.m624e$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m624e)[1,1])
       , sqrt (vcov (m624e)[1,1]+1^2*vcov (m624e)[5,5]+2*1*vcov (m624e)[1,5])
       , NA
       , sqrt (vcov (m624e)[1,1]+1^2*vcov (m624e)[4,4]+2*1*vcov (m624e)[1,4]))
  , c (sum.m624f$coef[c (1:2,4),2], rep (NA, 4), sum.m624f$coef[c (3,5),2], rep (NA, 2), sum.m624f$coef[6:8,2]
       , sqrt (vcov (m624f)[1,1])
       , sqrt (vcov (m624f)[1,1]+1^2*vcov (m624f)[5,5]+2*1*vcov (m624f)[1,5])
       , NA
       , sqrt (vcov (m624f)[1,1]+1^2*vcov (m624f)[4,4]+2*1*vcov (m624f)[1,4]))
  , rep (NA, 18)
  , c (sum.m614g$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m614g)[1,1])
       , sqrt (vcov (m614g)[1,1]+1^2*vcov (m614g)[4,4]+2*1*vcov (m614g)[1,4])
       , sqrt (vcov (m614g)[1,1]+1^2*vcov (m614g)[3,3]+2*1*vcov (m614g)[1,3])
       , sqrt (vcov (m614g)[1,1]+1^2*vcov (m614g)[3,3]+1^2*vcov (m614g)[4,4]+1^2*1^2*vcov (m614g)[5,5]+2*1*vcov (m614g)[1,3]+2*1*vcov (m614g)[1,4]+2*1*1*vcov (m614g)[1,5]+2*1*1*vcov (m614g)[3,4]+2*1*1^2*vcov (m614g)[3,5]+2*1*1^2*vcov (m614g)[4,5]))
  , c (sum.m624g$coef[c (1:2,4),2], rep (NA, 4), sum.m624g$coef[c (3,5),2], rep (NA, 5)
       , sqrt (vcov (m624g)[1,1])
       , sqrt (vcov (m624g)[1,1]+1^2*vcov (m624g)[5,5]+2*1*vcov (m624g)[1,5])
       , NA
       , sqrt (vcov (m624g)[1,1]+1^2*vcov (m624g)[4,4]+2*1*vcov (m624g)[1,4]))
  , rep (NA, 18)
  , c (sum.m614i$coef[1:7,2], rep (NA, 2+5)
       , sqrt (vcov (m614i)[1,1])
       , sqrt (vcov (m614i)[1,1]+1^2*vcov (m614i)[4,4]+2*1*vcov (m614i)[1,4])
       , sqrt (vcov (m614i)[1,1]+1^2*vcov (m614i)[3,3]+2*1*vcov (m614i)[1,3])
       , sqrt (vcov (m614i)[1,1]+1^2*vcov (m614i)[3,3]+1^2*vcov (m614i)[4,4]+1^2*1^2*vcov (m614i)[5,5]+2*1*vcov (m614i)[1,3]+2*1*vcov (m614i)[1,4]+2*1*1*vcov (m614i)[1,5]+2*1*1*vcov (m614i)[3,4]+2*1*1^2*vcov (m614i)[3,5]+2*1*1^2*vcov (m614i)[4,5]))
  , c (sum.m624i$coef[c (1:2,4),2], rep (NA, 4), sum.m624i$coef[c (3,5:7),2], rep (NA, 3)
       , sqrt (vcov (m624i)[1,1])
       , sqrt (vcov (m624i)[1,1]+1^2*vcov (m624i)[5,5]+2*1*vcov (m624i)[1,5])
       , NA
       , sqrt (vcov (m624i)[1,1]+1^2*vcov (m624i)[4,4]+2*1*vcov (m624i)[1,4]))))

odd <- seq (1, nrow (coefSplit04a)*2, by=2); even <- seq (2, nrow (coefSplit04a)*2, by=2)
(coefSplit04tab <- data.frame (rbind (coefSplit04a, seSplit04a))) ## warnings reported. Don't worry
rownames (coefSplit04tab) <- c (odd, even)
coefSplit04tab <- coefSplit04tab[order (as.numeric (rownames (coefSplit04tab))),]

rows <- c ("\\emph{growth}$_{t-1}$", "", "\\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}$_{t}$", "~~~~~$\\times$ \\emph{EAR}$_{t}$", "\\emph{EAR}$_{t}$", "", "\\emph{election}$_{t}$ $\\times$ \\emph{EAR}$_{t}$", "", "\\emph{election (other year)}$_{t}$", "", "\\emph{growth}$_{t-1}$", "~~~~~$\\times$ \\emph{election (other year)}$_{t}$"
           , "\\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{growth}$_{t-1}$ $\\times$ \\emph{election}", "~~~~~\\emph{(executive $+$ legislative)}$_{t}$", "\\emph{GDP per capita}$_{t-1}$ (log)", "", "\\emph{oil and gas}", "~~~~~\\emph{per capita}$_{t-1}$ (log)", "\\emph{proportion of}", "~~~~~ \\emph{democratic neighbors}$_{t}$"
           , "no election (closed)", "", "no election (EAR)", "", "election (closed)", "", "election (EAR)", "")

(Ns00 <- cbind (
  c (sum.m604a$N, length (unique (sum.m604a$fe$idRegime)), length (unique (maddMain[maddMain$poor50==0,]$country)), length (unique (sum.m604a$fe$year.f)))
  , c (sum.m614a$N, length (unique (sum.m614a$fe$idRegime)), length (unique (maddMain[maddMain$poor50==0,]$country)), length (unique (sum.m614a$fe$year.f)))
  , c (sum.m614c$N, length (unique (sum.m614c$fe$idRegime)), length (unique (maddMain[maddMain$poor50==0,]$country)), length (unique (sum.m614c$fe$year.f)))
  , c (sum.m614e$N, length (unique (sum.m614e$fe$idRegime)), length (unique (maddMain[maddMain$poor50==0,]$country)), length (unique (sum.m614e$fe$year.f)))
  , c (sum.m614f$N, length (unique (sum.m614f$fe$idRegime)), length (unique (maddMain[maddMain$poor50==0 & !is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m614f$fe$year.f)))
  , c (sum.m624a$N, length (unique (sum.m624a$fe$idRegime)), length (unique (maddMain[maddMain$poor50==0,]$country)), length (unique (sum.m624a$fe$year.f)))
  , c (sum.m624e$N, length (unique (sum.m624e$fe$idRegime)), length (unique (maddMain[maddMain$poor50==0,]$country)), length (unique (sum.m624e$fe$year.f)))
  , c (sum.m624f$N, length (unique (sum.m624f$fe$idRegime)), length (unique (maddMain[maddMain$poor50==0 & !is.na (maddMain$oil_gas_valuePOP_2000_lag),]$country)), length (unique (sum.m624f$fe$year.f)))
  , c (sum.m614g$N, length (unique (sum.m614g$fe$idRegime)), length (unique (maddMain[maddMain$poor50==0,]$country)), length (unique (sum.m614g$fe$year.f)))
  , c (sum.m624g$N, length (unique (sum.m624g$fe$idRegime)), length (unique (maddMain[maddMain$poor50==0,]$country)), length (unique (sum.m624g$fe$year.f)))
  , c (sum.m614i$N, length (unique (sum.m614i$fe$idRegime)), length (unique (maddMain[maddMain$poor50==0,]$country)), length (unique (sum.m614i$fe$year.f)))
  , c (sum.m624i$N, length (unique (sum.m624i$fe$idRegime)), length (unique (maddMain[maddMain$poor50==0,]$country)), length (unique (sum.m624i$fe$year.f)))))

Header1 <- paste ("\\toprule & & & \\multicolumn{4}{c}{\\textbf{actual elections}} & & \\multicolumn{3}{c}{\\textbf{scheduled elections}} & & \\multicolumn{2}{c}{\\textbf{non-competitive}} & & \\multicolumn{2}{c}{\\textbf{legislative}} \\\\ \\cmidrule{4-7} \\cmidrule{9-11} \\cmidrule{13-14} \\cmidrule{16-17} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{growth} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{growth $\\times$} & \\multicolumn{1}{c}{growth $\\times$} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} & & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{} \\\\ \n")
Header3 <- paste ("& \\multicolumn{1}{c}{only} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{el. $\\times$ EAR} & \\multicolumn{1}{c}{el. $\\times$ EAR} & & \\multicolumn{1}{c}{only} & \\multicolumn{1}{c}{election} & \\multicolumn{1}{c}{election} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} & & \\multicolumn{1}{c}{actual} & \\multicolumn{1}{c}{sched.} \\\\ \\midrule \n")
Header4 <- paste ("& \\multicolumn{1}{c}{(1)} & & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} & & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
Header5 <- paste ("[2ex] \\multicolumn{17}{l}{\\emph{Marginal effect of \\emph{growth}$_{t-1}$ on $\\mathsf{Pr (breakdown_{t} = 1)}$}} \\\\ \\midrule \n")

n.obs <- paste ("\\midrule observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[1,12],0)), "} \\\\ \n")
n.reg <- paste ("regimes & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[2,12],0)), "} \\\\ \n")
n.ctry <- paste ("countries & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,1],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,2],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,3],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,4],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,5],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,6],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,7],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,8],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,9],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,10],0)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,11],0)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns00[3,12],0)), "} \\\\ \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 0
addtorow$pos[[5]] <- 28
addtorow$pos[[6]] <- 36
addtorow$pos[[7]] <- 36
addtorow$pos[[8]] <- 36
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , Header5
                       , n.obs, n.reg, n.ctry)
print (xtable (cbind (rows, parSE (coefSplit04tab, n.digit))
               , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
               , digits=n.digit
               , caption="Rich countries"
               , label="T:rSplitRich")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)

## (7.4.2) Figure A31

# (7.4.2.1) Marginal effect of growth (t-1) on Pr (breakdown t):

# creating the dataset for the plots
dPlotSplit04g <- as.data.frame (factor (rep (c (rep ("actual elections", 4), rep ("scheduled elections", 4)), 4)))
colnames (dPlotSplit04g) <- "dataset"
dPlotSplit04g$elType <- factor (c (rep ("competitive\n& executive", 16), rep ("executive\nnon-competitive", 8), rep ("legislative\nonly", 8)))
dPlotSplit04g$controls <- factor (c (rep ("no controls", 8), rep ("w/controls", 8), rep ("no controls", 16)))
dPlotSplit04g$effect <- factor (rep (c ("closed", "closed\n(election)", "EAR\n(no election)", "EAR\n(election)"), 8))

# marginal effect of growth and 95% CIs:
dPlotSplit04g$n <- Ns00[1,sort (rep (c (4,5,7:12), 4))]
dPlotSplit04g$estimate <- c (coefSplit04tab[c (29, 33, 31, 35),5], coefSplit04tab[c (29, 33, 31, 35),9]
                             , coefSplit04tab[c (29, 33, 31, 35),6], coefSplit04tab[c (29, 33, 31, 35),10]
                             , coefSplit04tab[c (29, 33, 31, 35),12], coefSplit04tab[c (29, 33, 31, 35),13]
                             , coefSplit04tab[c (29, 33, 31, 35),15], coefSplit04tab[c (29, 33, 31, 35),16])
dPlotSplit04g$se <- c (coefSplit04tab[c (29, 33, 31, 35)+1,5], coefSplit04tab[c (29, 33, 31, 35)+1,9]
                       , coefSplit04tab[c (29, 33, 31, 35)+1,6], coefSplit04tab[c (29, 33, 31, 35)+1,10]
                       , coefSplit04tab[c (29, 33, 31, 35)+1,12], coefSplit04tab[c (29, 33, 31, 35)+1,13]
                       , coefSplit04tab[c (29, 33, 31, 35)+1,15], coefSplit04tab[c (29, 33, 31, 35)+1,16])
dPlotSplit04g$ciLow <- with (dPlotSplit04g, estimate + se*qt (0.025, df=n))
dPlotSplit04g$ciHigh <- with (dPlotSplit04g, estimate + se*qt (0.975, df=n))
dPlotSplit04g <- dPlotSplit04g[!is.na (dPlotSplit04g$estimate),]
dPlotSplit04g$effect <- factor (dPlotSplit04g$effect, levels=c ("closed", "EAR\n(no election)", "closed\n(election)", "EAR\n(election)"), ordered=F)

# (7.4.2.2) Marginal effect of election (t) on Pr (breakdown t):
dPlotSplit04el <- as.data.frame (factor (c (rep ("actual elections", m*2), rep ("scheduled elections", m))))
colnames (dPlotSplit04el) <- "dataset"
dPlotSplit04el$elType <- factor (c (rep ("actual elections\n(closed)", m), rep ("actual elections\n(EARs)", m), rep ("scheduled elections", m)))
dPlotSplit04el$n <- c (rep (Ns00[1,4], m*2) ,rep (Ns00[1,7], m))
dPlotSplit04el$growth <- rep (seq (min (maddMain[maddMain$poor50==0,]$madddGDPHead_lag), max (maddMain[maddMain$poor50==0,]$madddGDPHead_lag), length.out=m), 3)
dPlotSplit04el$estimate <- with (dPlotSplit04el, ifelse (
  elType=="actual elections\n(closed)", sum.m614e$coef[2,1]+sum.m614e$coef[3,1]*growth, ifelse (
    elType=="actual elections\n(EARs)", sum.m614e$coef[2,1]+sum.m614e$coef[7,1]+(sum.m614e$coef[3,1]+sum.m614e$coef[5,1])*growth, sum.m624e$coef[2,1]+sum.m624e$coef[4,1]*growth)))
dPlotSplit04el$se <- with (dPlotSplit04el, ifelse (
  elType=="actual elections\n(closed)", sqrt (vcov (m614e)[2,2] + (growth^2)*vcov (m614e)[3,3] + (2*growth)*vcov (m614e)[2,3]), ifelse (
    elType=="actual elections\n(EARs)", sqrt (vcov (m614e)[2,2] + (growth^2)*vcov (m614e)[3,3] + (1^2)*vcov (m614e)[7,7] + (growth^2)*(1^2)*vcov (m614e)[5,5] + (2*growth)*vcov (m614e)[2,3] + (2*1)*vcov (m614e)[2,7] + (2*growth*1)*vcov (m614e)[2,5] + (2*growth*1)*vcov (m614e)[3,7] + (2*1*growth^2)*vcov (m614e)[3,5] + (2*growth*1^2)*vcov (m614e)[7,5]), sqrt (vcov (m624e)[2,2] + (growth^2)*vcov (m624e)[4,4] + (2*growth)*vcov (m624e)[2,4]))))
dPlotSplit04el$ciLow <- with (dPlotSplit04el, estimate + se*qt (0.025, df=n))
dPlotSplit04el$ciHigh <- with (dPlotSplit04el, estimate + se*qt (0.975, df=n))
dPlotSplit04el <- dPlotSplit04el[abs (dPlotSplit04el$growth) <= h.lim,]

# (7.4.2.3) Drawing the plots

# Main results for growth|elections (with and without controls)
(pEffectSplit01 <- ggplot (dPlotSplit04g[dPlotSplit04g$elType=="competitive\n& executive",]
                           , aes (x=effect, y=estimate, fill=controls, group=controls, color=controls))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# Main vs. Placebos for growth|elections
(pEffectSplit02 <- ggplot (dPlotSplit04g[dPlotSplit04g$controls=="no controls",]
                           , aes (x=effect, y=estimate, fill=elType, group=elType, color=elType))
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~dataset, scales="free")
  + geom_errorbar (width=cex.bars, aes (ymin=ciLow, ymax=ciHigh), position=dodge)
  + geom_point (shape=21, size=cex.text/7, position=dodge)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("")
  + ylab ("marginal effect of growth (t-1)\non Pr[breakdown (t)]")
  + theme (legend.position = "bottom", legend.title = element_blank ()))

# creating the histogram to show below the main plot
(pGrowthSplit <- ggplot (maddMain[maddMain$poor50==0 & abs (maddMain$madddGDPHead_lag) < 0.3,], aes (x=madddGDPHead_lag))
  + geom_histogram (bins=b, fill=col.hist)
  + theme_transparent ())

# Main results for elections|growth
(pEffectSplit03 <- ggplot (dPlotSplit04el, aes (x=growth, y=estimate))
  + annotation_custom (grob = ggplotGrob (pGrowthSplit), xmin = -h.lim, xmax = h.lim)
  + geom_hline (yintercept=0, linetype=2, colour=col.line)
  + facet_grid (facets=.~elType, scales="free")
  + geom_ribbon (aes (ymin=ciLow, ymax=ciHigh), alpha=0.4, fill=col.fill)
  + geom_line (size=cex.text/18, colour=col.estim)
  + theme_bw ()
  + theme (text=element_text (size=cex.text))
  + theme (strip.text.x = element_text (size = cex.text))
  + xlab ("growth (t-1)")
  + ylab ("marginal effect of election (t)\non Pr[breakdown (t)]"))

# (7.4.2.4) Exporting the plots
png ("Figures/fig_rSplitRich01.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSplit01
dev.off ()
png ("Figures/fig_rSplitRich02.png", w=plotWidth, h=plotWidth/aspect.ratio)
pEffectSplit02
dev.off ()
png ("Figures/fig_rSplitRich03.png", w=plotWidth, h=plotWidth/(aspect.ratio*1.2))
pEffectSplit03
dev.off ()





### (8) Other tables: A1-A2 and A4-A5

## (8.1) Table A1: List of regimes included in the sample

# creating the regime-specific dataset
regs <- as.data.frame (with (maddMain, names (by (startyear, idRegime, max))))
colnames (regs) <- "idRegime"
regs$beg.y <- with (maddMain, by (startyear, idRegime, unique))[]
regs$end.y <- with (maddMain, by (year, idRegime, max))[]
regs$closed <- with (maddMain, by (closed, idRegime, max))[]
regs$ear <- with (maddMain, by (ear, idRegime, max))[]
regs$fail <- with (maddMain, by (fail, idRegime, max))[]
regs <- merge (regs, unique (maddMain[,c ("idRegime", "country", "howEnded")]), by="idRegime", all.x=T, all.y=T)

regs <- regs[order (regs$beg.y),]
regs <- regs[order (regs$country),]

# updating some variables
regs$end.y <- with (regs, ifelse (fail==0, NA, end.y))

regs$howEnded <- as.character (regs$howEnded)
regs[regs$howEnded=="in office",]$howEnded <- "N/A"

regs$idRegime <- as.character (regs$idRegime)
regs$idRegime <- sub ("Central African Republic", regs$idRegime, replacement="Cen. Af. Rep.")
regs$idRegime <- sub ("Democratic Republic of Congo", regs$idRegime, replacement="DR Congo")
regs$idRegime <- sub ("Dominican Republic", regs$idRegime, replacement="Dom. Republic")

Header1 <- paste ("\\toprule \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{begin} & \\multicolumn{1}{c}{end} & \\multicolumn{1}{c}{closed} & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{how} & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{begin} & \\multicolumn{1}{c}{end} & \\multicolumn{1}{c}{closed} & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{how} \\\\ \n")
Header2 <- paste ("\\multicolumn{1}{c}{Regime ID} & \\multicolumn{1}{c}{year} & \\multicolumn{1}{c}{year} & \\multicolumn{1}{c}{auth.} & \\multicolumn{1}{c}{EAR} & \\multicolumn{1}{c}{ended} & \\multicolumn{1}{c}{Regime ID} & \\multicolumn{1}{c}{year} & \\multicolumn{1}{c}{year} & \\multicolumn{1}{c}{auth.} & \\multicolumn{1}{c}{EAR} & \\multicolumn{1}{c}{ended} \\\\ [0.75ex] \\midrule \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$command <- c (Header1, Header2)
print (xtable (cbind (regs[c (1:41, 83:127, 173:215),c ("idRegime", "beg.y", "end.y", "closed", "ear", "howEnded")], regs[c (42:82, 128:172, 216:258),c ("idRegime", "beg.y", "end.y", "closed", "ear", "howEnded")])
               , align=c("l","l","c","c","c","c","l","l","c","c","c","c","l")
               , digits=n.digit
               , caption="Authoritarian regimes included in the analysis"
               , label="T:regimes")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="scriptsize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow)


## (8.2) Table A2: Breakdowns in election years

# selecting the observations and variables of interest and re-factorizing
regend <- baseFull[baseFull$fail==1 ## breakdown years only
               & !is.na (baseFull$timingE)
               & (baseFull$regime=="closed" | baseFull$regime=="EAR") ## closed regimes or EARs only; indirect regimes and oligarchies excluded
               , c ("country", "idRegime", "enddate", "regime", "timingE", "comE", "madddGDPHead_lag")]
regend$idRegime <- factor (regend$idRegime)
regend$regime <- factor (regend$regime)
regend$timingE <- factor (regend$timingE)

regend <- regend[order (regend$enddate),]
regend <- regend[order (regend$country),]
summary (regend)

# coding cases in which the election took place before the breakdown
regend$before <- with (regend, ifelse (timingE=="before" | timingE=="before and after" | timingE=="before and transitional", 1, 0))

# for elections that occurred BEFORE the breakdown, only include those cases in which (a) there is economic data; and (b) the election was competitive
summary (regend[!is.na (regend$madddGDPHead_lag) & regend$before==1 & regend$comE==1,])
regend[regend$before==1 & regend$comE==1,]

# for elections that occurred AFTER the breakdown, all elections for which there is economic data are coded as non-competitive. Check
summary (regend[!is.na (regend$madddGDPHead_lag) & regend$before==0,])
regend[regend$before==0,] ## only 3 of these elections were non-competitive:
# Congo 60-63
# Paraguay 48-54
# Togo 60-63

# excluding them:
regend$exclude <- 0
regend[regend$idRegime=="Congo 60-63",]$exclude <- 1
regend[regend$idRegime=="Paraguay 48-54",]$exclude <- 1
regend[regend$idRegime=="Togo 60-63",]$exclude <- 1
regend[regend$exclude==1,]  ## all's well

elbefore <- regend[!is.na (regend$madddGDPHead_lag) & regend$before==1 & regend$comE==1,c ("idRegime", "enddate", "regime")]
elafter <- regend[!is.na (regend$madddGDPHead_lag) & regend$before==0 & regend$exclude==0,c ("idRegime", "enddate", "regime")]
summary (elbefore); summary (elafter)
nrow (elbefore); nrow (elafter)

# binding and building the table
(elbds <- cbind (
  rbind (as.matrix (elbefore), matrix (rep (NA, (nrow (elafter) - nrow (elbefore)) * ncol (elbefore)), ncol=ncol (elbefore)))  ## adding NA's at the bottom
  , rep (NA, nrow (elafter))
  , as.matrix (elafter)))

Header1 <- paste ("\\toprule \\multicolumn{3}{c}{\\textbf{Election included in analysis}} & & \\multicolumn{3}{c}{\\textbf{Election not included in analysis}} \\\\ \\cmidrule{1-3} \\cmidrule{5-7} \n")
Header2 <- paste ("\\multicolumn{1}{c}{regime ID} & \\multicolumn{1}{c}{end date} & \\multicolumn{1}{c}{type} & & \\multicolumn{1}{c}{regime ID} & \\multicolumn{1}{c}{end date} & \\multicolumn{1}{c}{type} \\\\ \\midrule \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$command <- c (Header1, Header2)
print (xtable (elbds
               , align=c("l","l","c","c","c","l","c","c")
               , caption="Regimes that broke down in a year in which there was an election"
               , label="T:breakdowns")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow) ## warnings reported. Don't worry


## (8.3) Table A4: Agreement between alternative EAR classifications
(tCodings01 <- rbind (
  
  ## Original sample
  with (baseMain[!is.na (baseMain$closed) & baseMain$closed==1,]
        , c (sum (!is.na (closed) & closed) / sum (closed), sum (!is.na (ear) & ear) / sum (closed), sum (is.na (closed)==T) / sum (closed)
             , sum (!is.na (closedLIED) & closedLIED) / sum (closed), sum (!is.na (earLIED) & earLIED) / sum (closed), sum (is.na (closedLIED)==T) / sum (closed)
             , sum (!is.na (closedVDem) & closedVDem) / sum (closed), sum (!is.na (earVDem) & earVDem) / sum (closed), sum (is.na (closedVDem)==T) / sum (closed)))
  , with (baseMain[!is.na (baseMain$ear) & baseMain$ear==1,]
          , c (sum (!is.na (closed) & closed) / sum (ear), sum (!is.na (ear) & ear) / sum (ear), sum (is.na (ear)==T) / sum (ear)
               , sum (!is.na (closedLIED) & closedLIED) / sum (ear), sum (!is.na (earLIED) & earLIED) / sum (ear), sum (is.na (earLIED)==T) / sum (ear)
               , sum (!is.na (closedVDem) & closedVDem) / sum (ear), sum (!is.na (earVDem) & earVDem) / sum (ear), sum (is.na (earVDem)==T) / sum (ear)))
  
  ## LIED
  , with (baseMain[!is.na (baseMain$closedLIED==1) & baseMain$closedLIED==1,]
          , c (sum (!is.na (closed) & closed) / sum (closedLIED), sum (!is.na (ear) & ear) / sum (closedLIED), sum (is.na (closed)==T) / sum (closedLIED)
               , sum (!is.na (closedLIED) & closedLIED) / sum (closedLIED), sum (!is.na (earLIED) & earLIED) / sum (closedLIED), sum (is.na (closedLIED)==T) / sum (closedLIED)
               , sum (!is.na (closedVDem) & closedVDem) / sum (closedLIED), sum (!is.na (earVDem) & earVDem) / sum (closedLIED), sum (is.na (closedVDem)==T) / sum (closedLIED)))
  , with (baseMain[!is.na (baseMain$earLIED==1) & baseMain$earLIED==1,]
          , c (sum (!is.na (closed) & closed) / sum (earLIED), sum (!is.na (ear) & ear) / sum (earLIED), sum (is.na (ear)==T) / sum (earLIED)
               , sum (!is.na (closedLIED) & closedLIED) / sum (earLIED), sum (!is.na (earLIED) & earLIED) / sum (earLIED), sum (is.na (earLIED)==T) / sum (earLIED)
               , sum (!is.na (closedVDem) & closedVDem) / sum (earLIED), sum (!is.na (earVDem) & earVDem) / sum (earLIED), sum (is.na (earVDem)==T) / sum (earLIED)))
  
  ## V-Dem
  , with (baseMain[!is.na (baseMain$closedVDem==1) & baseMain$closedVDem==1,]
          , c (sum (!is.na (closed) & closed) / sum (closedVDem), sum (!is.na (ear) & ear) / sum (closedVDem), sum (is.na (closed)==T) / sum (closedVDem)
               , sum (!is.na (closedLIED) & closedLIED) / sum (closedVDem), sum (!is.na (earLIED) & earLIED) / sum (closedVDem), sum (is.na (closedLIED)==T) / sum (closedVDem)
               , sum (!is.na (closedVDem) & closedVDem) / sum (closedVDem), sum (!is.na (earVDem) & earVDem) / sum (closedVDem), sum (is.na (closedVDem)==T) / sum (closedVDem)))
  , with (baseMain[!is.na (baseMain$earVDem==1) & baseMain$earVDem==1,]
          , c (sum (!is.na (closed) & closed) / sum (earVDem), sum (!is.na (ear) & ear) / sum (earVDem), sum (is.na (ear)==T) / sum (earVDem)
               , sum (!is.na (closedLIED) & closedLIED) / sum (earVDem), sum (!is.na (earLIED) & earLIED) / sum (earVDem), sum (is.na (earLIED)==T) / sum (earVDem)
               , sum (!is.na (closedVDem) & closedVDem) / sum (earVDem), sum (!is.na (earVDem) & earVDem) / sum (earVDem), sum (is.na (earVDem)==T) / sum (earVDem)))))

# using two decimal places and adding empty columns
tCodings02 <- matrix (sprintf ("%.2f", tCodings01), nrow=6, ncol=9)
(tCodings03 <- cbind (rep ("", nrow (tCodings02)), tCodings02[,1:3], rep ("", nrow (tCodings02)), tCodings02[,4:6], rep ("", nrow (tCodings02)), tCodings02[,7:9]))

rows <- rep (c ("closed", "EAR"), 3)

Header1 <- paste ("\\toprule & & \\multicolumn{3}{c}{\\textbf{main}} & & \\multicolumn{3}{c}{\\textbf{LIED}} & & \\multicolumn{3}{c}{\\textbf{V-Dem}} \\\\ \\cmidrule{3-5} \\cmidrule{7-9} \\cmidrule{11-13} \n")
Header2 <- paste ("\\multicolumn{1}{c}{(a) \\emph{Main sample}} & & \\multicolumn{1}{c}{closed} & \\multicolumn{1}{c}{EAR} & \\multicolumn{1}{c}{NA's} & & \\multicolumn{1}{c}{closed} & \\multicolumn{1}{c}{EAR} & \\multicolumn{1}{c}{NA's} & & \\multicolumn{1}{c}{closed} & \\multicolumn{1}{c}{EAR} & \\multicolumn{1}{c}{NA's} \\\\ \\midrule \n")
Header3 <- paste ("[2ex] \\multicolumn{13}{l}{(b) \\emph{LIED sample}} \\\\ \\midrule \n")
Header4 <- paste ("[2ex] \\multicolumn{13}{l}{(c) \\emph{V-Dem sample}} \\\\ \\midrule \n")

addtorow <- list()
addtorow$pos <- list()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 2
addtorow$pos[[4]] <- 4
addtorow$command <- c (Header1, Header2, Header3, Header4)
print (xtable (  cbind (rows, tCodings03)
                 , align=c("l","l","r","r","r","r","r","r","r","r","r","r","r","r")
                 , digits=2
                 , caption="{Agreement between alternative EAR classifictions}"
                 , label="T:ears")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="small"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow  )


## (8.4) Table A5: Descriptive statistics
(tDescriptive <- rbind (
  with (maddMain, rbind (
    
    # Outcome(s)
    c (mean (fail, na.rm=T), sd (fail, na.rm=T), rep (NA, 4), min (fail, na.rm=T), max (fail, na.rm=T))
    , c (mean (endInsider, na.rm=T), sd (endInsider, na.rm=T), rep (NA, 4), min (endInsider, na.rm=T), max (endInsider, na.rm=T))
    , c (mean (endOutsider, na.rm=T), sd (endOutsider, na.rm=T), rep (NA, 4), min (endOutsider, na.rm=T), max (endOutsider, na.rm=T))
    , c (mean (endVoluntary, na.rm=T), sd (endVoluntary, na.rm=T), rep (NA, 4), min (endVoluntary, na.rm=T), max (endVoluntary, na.rm=T))
    , c (mean (tta, na.rm=T), sd (tta, na.rm=T), rep (NA, 4), min (tta, na.rm=T), max (tta, na.rm=T))
    , c (mean (ttd2, na.rm=T), sd (ttd2, na.rm=T), rep (NA, 4), min (ttd2, na.rm=T), max (ttd2, na.rm=T))
    , c (mean (protestD, na.rm=T), sd (protestD, na.rm=T), rep (NA, 4), min (protestD, na.rm=T), max (protestD, na.rm=T))
    , c (mean (protestViolentD, na.rm=T), sd (protestViolentD, na.rm=T), rep (NA, 4), min (protestViolentD, na.rm=T), max (protestViolentD, na.rm=T))
    , c (mean (coup, na.rm=T), sd (coup, na.rm=T), rep (NA, 4), min (coup, na.rm=T), max (coup, na.rm=T))
    , c (mean (coupSuc, na.rm=T), sd (coupSuc, na.rm=T), rep (NA, 4), min (coupSuc, na.rm=T), max (coupSuc, na.rm=T))
    , c (mean (coupFail, na.rm=T), sd (coupFail, na.rm=T), rep (NA, 4), min (coupFail, na.rm=T), max (coupFail, na.rm=T))
    
    # Economic growth
    , c (mean (madddGDPHead_lag, na.rm=T), sd (madddGDPHead_lag, na.rm=T), rep (NA, 4), min (madddGDPHead_lag, na.rm=T), max (madddGDPHead_lag, na.rm=T))
  ))
  , with (pwtMain, c (mean (pwtdGDPHead_lag, na.rm=T), sd (pwtdGDPHead_lag, na.rm=T), rep (NA, 4), min (pwtdGDPHead_lag, na.rm=T), max (pwtdGDPHead_lag, na.rm=T)))
  , with (wdiMain, c (mean (wdidGDPHead_lag, na.rm=T), sd (wdidGDPHead_lag, na.rm=T), rep (NA, 4), min (wdidGDPHead_lag, na.rm=T), max (wdidGDPHead_lag, na.rm=T)))
  , with (maddMain, c (mean (maddRec50_lag, na.rm=T), sd (maddRec50_lag, na.rm=T), rep (NA, 4), min (maddRec50_lag, na.rm=T), max (maddRec50_lag, na.rm=T)))
  
  # EARs
  , with (maddMain, c (mean (ear, na.rm=T), sd (ear, na.rm=T), rep (NA, 4), min (ear, na.rm=T), max (ear, na.rm=T)))
  , with (maddMain2lied, c (mean (earLIED, na.rm=T), sd (earLIED, na.rm=T), rep (NA, 4), min (earLIED, na.rm=T), max (earLIED, na.rm=T)))
  , with (maddMain2vdem, c (mean (earVDem, na.rm=T), sd (earVDem, na.rm=T), rep (NA, 4), min (earVDem, na.rm=T), max (earVDem, na.rm=T)))
  
  # Actual elections
  , with (maddMain, rbind (
    c (mean (comE, na.rm=T), sd (comE, na.rm=T), rep (NA, 4), min (comE, na.rm=T), max (comE, na.rm=T))
    , c (mean (nocomE, na.rm=T), sd (nocomE, na.rm=T), rep (NA, 4), min (nocomE, na.rm=T), max (nocomE, na.rm=T))
    , c (mean (comL2, na.rm=T), sd (comL2, na.rm=T), rep (NA, 4), min (comL2, na.rm=T), max (comL2, na.rm=T))
    
    # Scheduled elections
    , c (mean (yComEfThis_year, na.rm=T), sd (yComEfThis_year, na.rm=T), rep (NA, 4), min (yComEfThis_year, na.rm=T), max (yComEfThis_year, na.rm=T))
    , c (mean (yComEfOther_year, na.rm=T), sd (yComEfOther_year, na.rm=T), rep (NA, 4), min (yComEfOther_year, na.rm=T), max (yComEfOther_year, na.rm=T))
    , c (mean (ynoComEfThis_year, na.rm=T), sd (ynoComEfThis_year, na.rm=T), rep (NA, 4), min (ynoComEfThis_year, na.rm=T), max (ynoComEfThis_year, na.rm=T))
    , c (mean (ynoComEfOther_year, na.rm=T), sd (ynoComEfOther_year, na.rm=T), rep (NA, 4), min (ynoComEfOther_year, na.rm=T), max (ynoComEfOther_year, na.rm=T))
    , c (mean (yComOnlyLfThis_year, na.rm=T), sd (yComOnlyLfThis_year, na.rm=T), rep (NA, 4), min (yComOnlyLfThis_year, na.rm=T), max (yComOnlyLfThis_year, na.rm=T))
    , c (mean (yComOnlyLfOther_year, na.rm=T), sd (yComOnlyLfOther_year, na.rm=T), rep (NA, 4), min (yComOnlyLfOther_year, na.rm=T), max (yComOnlyLfOther_year, na.rm=T))

    # Controls and conditioning variables
    , c (mean (maddGDPHead_lag, na.rm=T)/1000, sd (maddGDPHead_lag, na.rm=T)/1000, rep (NA, 4), min (maddGDPHead_lag, na.rm=T)/1000, max (maddGDPHead_lag, na.rm=T)/1000)
    , c (mean (oil_gas_valuePOP_2000_lag, na.rm=T)/1000, sd (oil_gas_valuePOP_2000_lag, na.rm=T)/1000, rep (NA, 4), min (oil_gas_valuePOP_2000_lag, na.rm=T)/1000, max (oil_gas_valuePOP_2000_lag, na.rm=T)/1000)
    , c (mean (propDemo, na.rm=T), sd (propDemo, na.rm=T), rep (NA, 4), min (propDemo, na.rm=T), max (propDemo, na.rm=T))
    , c (mean (party2, na.rm=T), sd (party2, na.rm=T), rep (NA, 4), min (party2, na.rm=T), max (party2, na.rm=T))
    , c (mean (poor50, na.rm=T), sd (poor50, na.rm=T), rep (NA, 4), min (poor50, na.rm=T), max (poor50, na.rm=T))
  ))))

# adding the within-regime means and SDs
tDescriptive[,4] <- c (mean (as.numeric (with (maddMain, by (fail, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (endInsider, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (endOutsider, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (endVoluntary, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (tta, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (ttd2, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (protestD, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (protestViolentD, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (coup, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (coupSuc, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (coupFail, idRegime, mean, na.rm=T))[]), na.rm=T)
                       
                       , mean (as.numeric (with (maddMain, by (madddGDPHead_lag, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (pwtMain, by (pwtdGDPHead_lag, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (wdiMain, by (wdidGDPHead_lag, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (maddRec50_lag, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (ear, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain2lied, by (earLIED, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain2vdem, by (earVDem, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (comE, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (nocomE, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (comL2, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (yComEfThis_year, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (yComEfOther_year, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (ynoComEfThis_year, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (ynoComEfOther_year, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (yComOnlyLfThis_year, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (yComOnlyLfThis_year, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (maddGDPHead_lag/1000, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (oil_gas_valuePOP_2000_lag/1000, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (propDemo, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (party2, idRegime, mean, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (poor50, idRegime, mean, na.rm=T))[]), na.rm=T)
)
tDescriptive[,5] <- c (mean (as.numeric (with (maddMain, by (fail, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (endInsider, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (endOutsider, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (endVoluntary, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (tta, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (ttd2, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (protestD, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (protestViolentD, idRegime, mean))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (coup, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (coupSuc, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (coupFail, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (madddGDPHead_lag, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (pwtMain, by (pwtdGDPHead_lag, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (wdiMain, by (wdidGDPHead_lag, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (maddRec50_lag, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (ear, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain2lied, by (earLIED, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain2vdem, by (earVDem, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (comE, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (nocomE, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (comL2, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (yComEfThis_year, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (yComEfOther_year, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (ynoComEfThis_year, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (ynoComEfOther_year, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (yComOnlyLfThis_year, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (yComOnlyLfThis_year, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (maddGDPHead_lag/1000, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (oil_gas_valuePOP_2000_lag/1000, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (propDemo, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (party2, idRegime, sd, na.rm=T))[]), na.rm=T)
                       , mean (as.numeric (with (maddMain, by (poor50, idRegime, sd, na.rm=T))[]), na.rm=T)
)
rows <- c (
  
  ## (a) outcome variables
  "\\emph{breakdown}$_{t}$"
  , "\\emph{end (insider)}$_{t}$"
  , "\\emph{end (outsider)}$_{t}$"
  , "\\emph{end (voluntary)}$_{t}$"
  , "\\emph{other autocracy}$_{t+1}$"
  , "\\emph{democracy}$_{t+1}$"
  , "\\emph{protest}$_{t}$"
  , "\\emph{violent protest}$_{t}$"
  , "\\emph{coup attempt}$_{t}$"
  , "\\emph{successful coup}$_{t}$"
  , "\\emph{unsuccessful coup}$_{t}$"
  
  ## (b) economic performance
  , "\\emph{growth}$_{t-1}$ (Maddison)"
  , "\\emph{growth}$_{t-1}$ (PWT v9.0)"
  , "\\emph{growth}$_{t-1}$ (WDI)"
  , "\\emph{recession}$_{t-1}$ (Maddison)"
  
  ## (c) regime type
  , "\\emph{EAR}$_{t}$"
  , "\\emph{EAR (LIED)}$_{t}$"
  , "\\emph{EAR (V-Dem)}$_{t}$"
  
  ## (d) actual elections
  , "\\emph{executive (competitive)}$_{t}$"
  , "\\emph{executive (non-competitive)}$_{t}$"
  , "\\emph{legislative (competitive)}$_{t}$"
  
  ## (e) scheduled elections
  , "\\emph{executive (competitive) (this year)}$_{t}$"
  , "\\emph{executive (competitive) (other year)}$_{t}$"
  , "\\emph{executive (non-competitive) (this year)}$_{t}$"
  , "\\emph{executive (non-competitive) (other year)}$_{t}$"
  , "\\emph{legislative only (competitive) (this year)}$_{t}$"
  , "\\emph{legislative only (competitive) (other year)}$_{t}$"
  
  ## (f) controls and conditioning variables
  , "\\emph{GDP per capita}$_{t-1}$ (th. 1990 Int. GK\\$)"
  , "\\emph{oil and gas per capita}$_{t-1}$ (th. 2000 dollars)"
  , "\\emph{prop. democratic neighbors}$_{t}$"
  , "\\emph{party-based regime}"
  , "\\emph{poor country}"
)

Header1 <- paste ("\\toprule & \\multicolumn{2}{c}{\\textbf{pooled sample}} & & \\multicolumn{2}{c}{\\textbf{within-regime}} & & & \\\\ \\cmidrule{2-3} \\cmidrule{5-6} \n")
Header2 <- paste ("& \\multicolumn{1}{c}{mean} & \\multicolumn{1}{c}{std. dev.} & & \\multicolumn{1}{c}{mean} & \\multicolumn{1}{c}{std. dev.} & & \\multicolumn{1}{c}{min.} & \\multicolumn{1}{c}{max.} \\\\ \\midrule \n")
Header3 <- paste ("\\midrule \n")

addtorow <- list()
addtorow$pos <- list()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 1
addtorow$pos[[4]] <- 11
addtorow$pos[[5]] <- 15
addtorow$pos[[6]] <- 18
addtorow$pos[[7]] <- 21
addtorow$pos[[8]] <- 27
addtorow$command <- c (Header1, Header2, Header3
                       , Header3, Header3, Header3, Header3, Header3
)
print (xtable (  cbind (rows, round (tDescriptive, n.digit))
                 , align=c("l","l","r","r","r","r","r","r","r","r")
                 , digits=2
                 , caption="{Descriptive statistics}"
                 , label="T:descriptive")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow  )

# reported sample sizes:
nrow (maddMain); length (unique (maddMain$idRegime)); length (unique (maddMain$country))




